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

281
Views
Nginx Forward Request to Different Port

I am using fastapi, gunicorn and nginx on my server

My web application main.py is

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
def read_root():
    return {"Hello": "World"}


@app.get("/items/{item_id}")
def read_item(item_id: int, q: str = None):
    return {"item_id": item_id, "q": q}

I run the code above to listen two ports 8080 and 8081

gunicorn -k uvicorn.workers.UvicornWorker --bind "0.0.0.0:8080" --log-level debug main:app
gunicorn -k uvicorn.workers.UvicornWorker --bind "0.0.0.0:8081" --log-level debug main:app

Then in my nginx.conf

server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  127.0.0.1;
    root         /usr/share/nginx/html;
    include /etc/nginx/default.d/*.conf;

    location / {
            proxy_pass http://127.0.0.1:8080/;
    }
    location /another {
            proxy_pass http://127.0.0.1:8081/;
    }
}

I expect the results like below

xxx.xxx.xxx.xxx/    =>     {"Hello":"World"}
xxx.xxx.xxx.xxx/items/1  =>  {"item_id":1,q:null}
xxx.xxx.xxx.xxx/another    =>     {"Hello":"World"}
xxx.xxx.xxx.xxx/another/items/1  =>  {"item_id":1,q:null}

But I get

xxx.xxx.xxx.xxx/    =>     {"Hello":"World"}
xxx.xxx.xxx.xxx/items/1  =>  {"item_id":1,q:null}
xxx.xxx.xxx.xxx/another    =>     {"Hello":"World"}
xxx.xxx.xxx.xxx/another/items/1  =>  {"Detail": "Not Found"}  // Here is the problem

How can I forward the request as I expect?

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!