d-juwg
Last Updated: February 25, 2016
·
618
· markus-perl
10620301 745710515470370 5763874756421604255 o

HowTo Use Nginx to deliver nodejs pages

The nodejs integrated webserver does not scale very well under high load especially if you want to use https.

For this usage case you can simply put nginx in front of nodejs. nginx is much more stable in handling encrypted connections and performes very well even under a huge amount of requests:

server {

    listen 443 ssl;

        server_tokens off;

        ssl_certificate /etc/nginx/yourpage.crt;
        ssl_certificate_key /etc/nginx/yourpage.key;
        ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;
        ssl_session_cache shared:SSL:100m;
        ssl_session_timeout 10m;

        access_log off;
        error_log /dev/null;

    location / {
            proxy_redirect off;
            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   Connection "";
            proxy_http_version 1.1;
            proxy_pass         http://your-nodejs-server:port;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        }
}
Say Thanks
Respond