Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx changes POST to GET using proxy_pass

Tags:

post

nginx

proxy

I want to use Nginx create a gateway to receive requests and pass them along to a network of microservices.

What I need Nginx to do is just act as a proxy server, taking the requests, passing them along to whatever service, and returning the response without any changes.

This is my configuration for my local setup:

server {
    listen 8080;

    location /api/register/ {
        proxy_pass http://micro_auth_backend:8082;
    }

    location /api/location/ {
        proxy_pass http://localhost:8088;
    }

}

It works correctly for GET requests, but when doing a POST call, the server will always receive a GET response.

I have tried adding some more configs inside the location, such as this example below, but so far nothing has worked:

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

Any suggestions would be appreciated. Thank you

like image 466
Lucas Andrade Avatar asked Apr 12 '26 21:04

Lucas Andrade


1 Answers

Just removed the trailing slash on location:

location /api/register {
    proxy_pass http://micro_auth_backend:8082;
}

Now it works.

like image 128
Lucas Andrade Avatar answered Apr 15 '26 09:04

Lucas Andrade



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!