Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

274
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda