Here is my nginx conf for my Flask app:
server {
listen 8888;
location /dev1 {
proxy_pass http://127.0.0.1:8000/;
}
location /prod1 {
proxy_pass http://127.0.0.1:8001/;
}
location /prod2 {
proxy_pass http://127.0.0.1:8002/;
}
location /prod3 {
proxy_pass http://127.0.0.1:8003/;
}
}
Now if I go to myapp/prod1, it is working correctly, however, clicking on any links on the website redirect me to /link1, whereas I want to keep the prefix so that clicking would redirect me to /prod1/link1. I am not sure if this is a problem that I need to fix in Flask or nginx, some of my route look like this:
@app.route("/")
@app.route("/link1")
def link1(....):
...
2
Answers
You can do it with Flask Blueprints when your register them.
Check the documentation for full example: https://flask.palletsprojects.com/en/2.0.x/blueprints/
When you are using a wsgi server, e.g. gunicorn, you can use this command:
Just use different prefixes for your different Flask apps.
Also see this wonderful blog post https://dlukes.github.io/flask-wsgi-url-prefix.html