I have a Flask application that is currently being served on a machine (call it first_vm
) using the following command in supervisord
:
gunicorn run:app -b 0.0.0.0:8002 -k socketio.sgunicorn.GeventSocketIOWorker --workers 1
This application is also reverse proxied locally on port 80
by nginx
, such that http://first_vm/
will serve the application as expected.
What I would like to do is to reverse proxy the application on a different server (say second_vm
), such that http://second_vm/my_app
serves the application by hitting gunicorn
on first_vm:8002
.
This is the nginx configuration I currently have on second_vm
:
location /my_app {
proxy_pass http://first_vm:8002/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
This configuration works fine in that it serves my application on http://second_vm/my_app
, but static files (e.g. JS/CSS) don't get served properly because the browser tries to fetch them from http://second_vm/
instead of http://second_vm/my_app
.
For example, Chrome will tell me that it Failed to load resource: the server responded with a status 404
in the following scenario:
http://second_vm/blueprint/static/css/bootstrap.min.css <-- what Chrome fails to fetch
http://second_vm/my_app/blueprint/static/css/bootstrap.min.css <-- what it should fetch
Could anyone help me make this work?