I have a gunicorn serving a flask application behind Apache using mod_proxy.
Gunicorn is on http://localhost:8080/
. Let's say my server is on http://example.com/
Sometimes when I post an invalid link to my server (like forgetting the trailing), let's say http://example.com/with-no-trailing-slash
, the user is redirected to http://localhost:8080/with-no-trailing-slash
which is not valid because there is no server on the client machine.
Do you know why it behaves like that? And how to fix this behavior?
To start gunicorn I do this: sudo gunicorn -b localhost:8080 app:app
<VirtualHost *:80>
ServerName example.com
ServerAlias example.com
DocumentRoot /opt/example
<Proxy *>
AuthType basic
AuthBasicAuthoritative Off
SetEnv proxy-chain-auth On
Order allow,deny
Allow from all
</Proxy>
# Let apache serve static files
ProxyPass /robots.txt !
ProxyPass /favicon.ico !
ProxyPass /static/ !
Alias /static/ /opt/example/app/static/
# Gunicorn handle the others
ProxyPass / http://localhost:8080/
# robots.txt et favicon.ico sont dans /path/to/django/project/static/
Alias /robots.txt /path/to/django/project/static/robots.txt
Alias /favicon.ico /path/to/django/project/static/favicon.ico
Alias /favicon.ico /path/to/django/project/static/favicon.ico
<Directory /path/to/django/project>
Order deny,allow
Allow from all
Options -Indexes
</Directory>
</VirtualHost>
If you need another config file, let me know!