Python Flask webapp simple proxy configuration to enable SSL / HTTPS with Apache

I have a working Python based webapp, Flask. (configured to work on http: // host: port)

I need to get it to work with https. I was provided with an Apache proxy that redirects all requests this way:

(Apache) https: // host / myApp -> http: // host: port (my Flask-based application). Where host: port is the standard configuration in which my application works fine.

I can contact the service and index page. However, there is a problem with access to all static content, for which the vi url_for method was requested (for example, ico, images, etc.).

Can you tell me any resources / information? Thanks in advance.

+3
source share
1 answer

We add a line to httpd.conf that processes / static / instead of proxing it to guniororn:

<VirtualHost oursite.com>

  # Tells apache where /static/ should go
  Alias /static/ /full/path/to/flask/app/static/

  # Proxy everything to gunicorn EXCEPT /static and favicon.ico
  ProxyPass /favicon.ico !
  ProxyPass /static !
  ProxyPass / http://gunicorn.oursite.com:4242/
  ProxyPassReverse / http://gunicorn.oursite.com:4242/

</VirtualHost>

This works because we have gunicorn and apache working in the same field, which may or may not work for you. You may need to copy static files to the apache host as part of your site deployment.

Probably the best way to do this, but it works for us.

+3
source

Source: https://habr.com/ru/post/1545608/


All Articles