I have 2 separate projects running on the same Linux server. Both projects based on Flask. Due to infrastructure restrictions I'm able to use only one HTTP Port on the server.

I would like to route user requests between the projects based on URL.

Example:

server-ip:port/url1 runs main.py from the 1st project

server-ip:port/url2 runs main.py from the 2nd project

How is better to do that?

Is it enough just to make a 3rd project which will perform request routing and run different main-files from other projects? Can you share your suggestions?

4 Replies 4

You don’t need a “3rd Flask project” to route between the two apps – that’s exactly what a **reverse proxy** like **nginx** is for.

The standard production pattern is:

- Each Flask app runs on its **own internal port** (localhost-only).

- **nginx** listens on the single public HTTP port.

- nginx uses `location` blocks to forward `/url1/...` to app1 and `/url2/...` to app2.

---

## 1. Run your Flask apps on different internal ports

Example:

# App 1

FLASK_APP=main.py flask run --host=127.0.0.1 --port=5001

# App 2

FLASK_APP=main.py flask run --host=127.0.0.1 --port=5002

And then nginx:

server {
    listen 80;
    server_name your.server.ip;  # or domain

    # Route /url1/... to Flask app 1
    location /url1/ {
        proxy_pass http://127.0.0.1:5001/;
        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-Proto $scheme;
    }

    # Route /url2/... to Flask app 2
    location /url2/ {
        proxy_pass http://127.0.0.1:5002/;
        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-Proto $scheme;
    }
}

Thank you so much! I've got your point. That was so simple ))

P.S. if you make it as an reply so I can mark it as a solution

I guess put both projects in a docker container but don't open them to any ports on the host to the server, use Nginx Proxy Manager in a third container with open port on the host and use the dockers internal ip of each container in Nginx Proxy Manager.

This is dead simple with Caddy

https://caddyserver.com

Your Reply

By clicking “Post Your Reply”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.