Node.js - Nginx 502 Bad Gateway on POST/PUT

October 25, 2014 12.9k views


I have a MEAN app and on localhost works fine.

I have a CentOs droplet with node.js and nginx, but that i make for example a submit form by POST or PUT, console returns "502 Bad Gateway".

Each time i restart nginx, shows:
nginx: [emerg] unknown directive "proxyhttpversion"

My conf in nginx:

server {
    listen 80;
    location / {
        proxy_pass http://localhost:3003;
        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;
        proxy_connect_timeout       300;
        proxy_send_timeout          300;
        proxy_read_timeout          300;
        send_timeout                300;

My niginx version is 1.0.15

Thanks for now. =D

1 comment
  • Usually when shown 502 error is the following:
    Nginx running as proxy for Apache web server.
    Nginx running with PHP-FPM daemon.
    Nginx running with other services as gateway.
    Bad buffering/timeout configuration.

    Are you running Nginx using PHP-FPM?

1 Answer
  • Err, that edit thing is really dangerous.

    You probably are running an older version of Nginx that does not support that directive. It was introduced in Nginx 1.1.4.

    Check what version of Nginx you're running:

    nginx -v
  • So...

    I update to Nginx to 1.6.2.

    Dont show more "nginx: [emerg] unknown directive "proxyhttpversion".

    But the POST/PUT form continue... Same error on console...
    " 502 Bad Gateway - 309ms"


  • Can you post the errors Nginx is throwing? Are you sure the backend is actually up and responding to requests?

  • Nginx log from my proxy:

    2014/10/25 15:53:41 [error] 993#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client:, server:, request: "POST /contributors HTTP/1.1", upstream: "http://[::1]:3003/users", host: "", referrer: ""
  • Well - it says what is wrong right there. I bet your application is not listening for connections on IPv6.

  • No, is no listening on IPv6.

    How i make to Nginx works just with IPv4?

  • Since you're doing proxypass to localhost it will be whatever resolves to localhost in your /etc/hosts-file that makes it bind to that interface. Change out localhost with in your proxypass and you'll pass it only to

Have another answer? Share your knowledge.