简体   繁体   中英

How to get POST requests through Nginx reverse proxy to Node/Express.js

I have a typical Express.js app with a POST route.

I have nginx acting as a reverse proxy to the Express server.

nginx properly sends incoming requests, but seems to drop the POST request Body.

Here is my nginx conf:

server {
  listen 80;

  server_name domain.com;

  location / {
    proxy_pass http://localhost:3000;
    proxy_redirect off;
    proxy_http_version 1.1;
    proxy_buffering off;
  }
}

EDIT:

Turns out my nginx config was fine, the error was somewhere else in the app, but it appeared like a nginx error. The above config works totally fine.

Turns out my nginx config was fine, the error was somewhere else in the app, but it appeared like a nginx error. The above config works totally fine.

Any luck with something like this?

server {
    listen 80;

    server_name domain.com;

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

Or maybe something more like this:

server {
    listen 0.0.0.0:80;
    server_name yourdomain.com yourdomain;
    access_log /var/log/nginx/yourdomain.log;

    location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy true;

      proxy_pass http://localhost:3000;
      proxy_redirect off;
    }
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM