Multiple backend servers accessible from a Flask server

flask, nginx, python

Solution

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.

Problem

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?

Original source