NGINX configuration for proxing to websocket/nodejs processs

By , Friday 29th November 2013 11:06 am

Here’s a simple configuration to allow nginx to proxy through to another process including forwarding websocket traffic.

A simple set up currently in use to proxy to a nodejs process which is also serving HTML. I’d like to improve the config so that nginx serves static content, but will look to do that later.

Improvements, suggestions please add to the comments (…and thanks).

server {
    listen 80;
    server_name example.com;
    return 301 https://example.com$request_uri;
}

server {
    listen       443;
    server_name  example.com;

    root /var/www/html/public;

    ssl                  on;
    ssl_certificate      /etc/ssl/private/ssl.cert;
    ssl_certificate_key  /etc/ssl/private/ssl.key;

    ssl_protocols  SSLv2 SSLv3 TLSv1;
    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers   on;

    proxy_connect_timeout 43200000;
    proxy_read_timeout 43200000;
    proxy_send_timeout 43200000;

    if ($ssl_protocol = "") {
        rewrite ^ https://$host$request_uri? permanent;
    }
    try_files $uri @proxysocket;

    location / {
        proxy_pass http://127.0.0.1:3000/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

Liked this post? Follow this blog to get more. 

Leave a Reply

You must be logged in to post a comment.

Panorama Theme by Themocracy

1 visitors online now
0 guests, 1 bots, 0 members
Max visitors today: 16 at 08:14 am UTC
This month: 17 at 19-09-2017 09:35 pm UTC
This year: 45 at 02-01-2017 10:28 pm UTC
All time: 130 at 28-03-2011 10:40 pm UTC