9

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!

2
  • Typically I would expect that to be the result of a trailing slash in your ProxyPass directive instead of omitting that. e.g. ProxyPass /app/ http://localhost:8080/app/ versus ProxyPasss /app http://..../app
    – HBruijn
    Sep 9, 2014 at 20:46
  • Yes, post the relevant sections of the config files.
    – MadHatter
    Sep 10, 2014 at 5:35

1 Answer 1

6

You're missing the reverse mapping which is precisely useful to Apache for redirection URLs rewriting. In 99% of cases, the forward and reverse mappings are the same.

Add this :

ProxyPassReverse / http://localhost:8080/

And reload Apache.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .