In my Flask configuration, I set SERVER_NAME to a domain, such as "app.example.com". I do this because I need to use url_for with _external URL. If SERVER_NAME is not set, Flask considers the server to be 127.0.0.1β000 (it actually works behind a reverse proxy) and returns an external URL, for example http: http://127.0.0.1:5000/location .
So far so good. But here is my problem: when setting SERVER_NAME, each URL returns 404. I see that each request goes to the server, to the correct URL, but Flask responds to 404. If you disable SERVER_NAME, the correct page will return.
I use Apache with ProxyPass and ProxyPassReverse (I know I would prefer to use Nginx, but this is a requirement). Here are the headers I add:
Header add Host "app.example.com" RequestHeader set Host "app.example.com" Header add X-Forwarded-Host "app.example.com" RequestHeader set X-Forwarded-Host "app.example.com"
Any ideas?
python flask apache
nathancahill
source share