Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

238
Views
How to properly use locations in Nginx

I have 2 APIs (one built with Flask and the other one with FastAPI):

-- home
   -- app_flask
          main_flask.py
   -- app_fastapi
          main_fastapy.py

I defined a get endpoint in both files:

main_flask.py

from flask import Flask
app = Flask(__name__)

@app.route("/hello_flask")
def hello():
    return {"result": "Welcome to Flask"}

main_fastapi.py

from fastapi import FastAPI
app = FastAPI()

@app.get("/hello_fastapi")
def hello():
    return {"result": "Welcome to FastAPI"}

The first one runs on port 8000 and the second one on port 8001

This is my /etc/nginx/sites-enabled/default file:

server {
    listen 80;
    server_name {here_my_IP};
    location /flask_app {
        proxy_pass http://127.0.0.1:8000;
    }

    location /fastapi_app {
        proxy_pass http://127.0.0.1:8001;
    }
}

But once everything is running, when I access to

http://myIP/flask_app/hello_flask

or

http://myIP/fastapi_app/hello_fastapi

I get this error:

{"error":["404 - Resource Not Found"]}

I don't get this error if I use location / {} instead of location /app {} on the default Nginx file and then I access to

http://myIP/hello_fastapi (for example in the case of the first API)

So I conclude that I am incorrectly routing the apps on the defaul configuration Nginx file.

How should I do it?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!