[FIXED] Multiple backend servers accessible from a Flask server

Issue

You need a front-end server that clients can connect to, and some clients are (transparently) redirected to another Flask application that handles the needs of a particular client (e.g. there could be different applications there is).

I also want to be able to add/remove/restart backend clients at any time without killing the main server for other clients.

What we ask of our clients:

  • Don’t detect that there is another server in the backend (URL must be the same host)
  • No need to re-enter credentials when redirected to another process

What is the best approach?

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.

Answered By – Miguel Grinberg

Answer Checked By – Cary Denson (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published