Report this

What is the reason for this report?

How to proxy Node.js error responses on NGINX?

Posted on July 26, 2017

I have an application server that is running a Sails.js Node application on top of NGINX. The application appears to be working correctly, however when the server accepts/rejects a request, the response body is empty. The response code is correct, however the body is completely empty. I can verify that the app is generating the correct responses using the applications debugging that I have in place.

This is the NGINX configuration that I have in place:

upstream local-upstream {
        server 127.0.0.1:8080;
        keepalive 64;
}
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        return 301 https://$host$request_uri;
}
server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        ssl on;
        ssl_certificate XXX;
        ssl_certificate_key XXX;
        ssl_prefer_server_ciphers on;

        ## OCSP Stapling
        resolver 127.0.0.1 8.8.8.8 8.8.4.4 valid=300s;
        resolver_timeout 5s;
        ssl_stapling on;
        ssl_stapling_verify on;
        ssl_trusted_certificate XXX;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        #server_name _;
        server_name app.quiqmath.com;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                #try_files $uri $uri/ =404;
                proxy_pass http://local-upstream;
                proxy_redirect off;
                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;
        }

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.