POST to NGINX proxy_pass works but I’m getting a 502 Bad Gateway on the client


This Content is from Stack Overflow. Question asked by bralley

what I’d like to achieve is the following:

client -> nginx proxy -> db server -> give response to client

This is what my nginx config looks like:

    server_name {site}.dev www.{site}.dev;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ =404;

    location /api {
            proxy_pass http://localhost:3000/api;
            # proxy_set_header Host $host;

For more context, from http://localhost:3000/api I am making a call to an express server on the database server that then makes the database request.

Now, I’m seeing on both nginxserver:3000 and dbserver:3000 that the requests are being received, yet I get a 502 bad gateway response on the client.

I’d like to be able to get the response from the database server on the client.

I’d appreciate any help, thank you !


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?