可以从Flask服务器访问多个后端服务器 [英] Multiple backend servers accessible from a Flask server
问题描述
我希望客户端:
- 没有检测到后端还有其他服务器(这个URL应该是同一个主机)
- 当它们被重定向到另一个进程时,不必重新输入它们的凭证
最好的办法是什么?
您描述的前端服务器是基本上被称为反向代理。
逆向代理接收来自客户端的请求,并将其转发给客户端无法直接访问的第二行内部服务器。通常,根据请求URL的某个方面决定将哪个内部服务器转发请求。例如,您可以为每个内部应用程序分配一个不同的子域。
在反向代理接收到内部服务器的响应后,将其转发给客户端如果这是它自己的回应。内部服务器的存在不会泄露给客户端。
只要所有的内部服务器共享相同的认证机制和用户数据库,解决认证就很简单。每个请求将带有认证信息。例如,这可以是由登录请求,直接用户凭证或某种类型的身份验证令牌设置的会话cookie。在所有情况下,您都可以在所有应用程序中以相同的方式验证登录。
Nginx 是一个流行的网页服务器,可以很好地作为反向代理。
I want to have a front-end server where my clients can connect, and depending on the client, be redirected (transparently) to another Flask application that will handle the specific client needs (eg. there can be different applications). I also want to be able to add / remove / restart those backend clients whenever I want without killing the main server for the other clients.
I'd like the clients to: - not detect that there are other servers in the backend (the URL should be the same host) - not have to reenter their credentials when they are redirected to the other process
What would be the best approach?
The front-end server that you describe is essentially what is known as a reverse proxy.
The reverse proxy receives requests from clients and forwards them to a second line of internal servers that clients cannot reach directly. Typically the decision of which internal server to forward a request to is made based on some aspect of the request URL. For example, you can assign a different sub-domain to each internal application.
After the reverse proxy receives a response from the internal server it forwards it on to the client as if it was its own response. The existence of internal servers is not revealed to the client.
Solving authentication is simple, as long as all your internal servers share the same authentication mechanism and user database. Each request will come with authentication information. This could for example be a session cookie that was set by the login request, direct user credentials or some type of authentication token. In all cases you can validate logins in the same way in all your applications.
Nginx is a popular web server that works well as a reverse proxy.
这篇关于可以从Flask服务器访问多个后端服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!