NginX fails to pass of POST request body when proxying requests to an Express backend from static bundle NginX fails to pass of POST request body when proxying requests to an Express backend from static bundle json json

NginX fails to pass of POST request body when proxying requests to an Express backend from static bundle


I figured out the problem. It was simple. I failed to pass the correct 'Content-Type' header to the proxy. I looked at the request output and saw this while expecting to pass JSON:

Content-Type: text/plain;charset=UTF-8

Express body-parser/json-parser didn't parse the body, and did not pass it to req.body.

Adding this into my /api proxy handler fixed things:

proxy_set_header content-type "application/json";

    location /api {        proxy_pass http://localhost:3001;        proxy_http_version 1.1;        proxy_set_header Upgrade $http_upgrade;        proxy_set_header Host $host;        proxy_set_header content-type "application/json";        proxy_cache_bypass $http_upgrade;        proxy_set_header Connection 'upgrade';        access_log /var/www/pocket-caravan.com/logs/logs.txt;    }


Might help other, so I have been in same problem as this, the url call is received but without the data. After written the nginx config as suggested in the accepted answer the problem still exist. Then I find out that I need to call the server not with http but with https. So if you still stuck like me then check your url.

Didn't know why the call with http is routed without data but it did.