Setup Nginx as the frondend server for Node.js - lifuzu/cafe GitHub Wiki

  1. Install Nginx:
sudo apt-get install nginx
  1. Start Nginx:
sudo service nginx start
  1. Check Nginx running:
    Get the machine IP: ifconfig eth0 | grep inet | awk '{ print $2 }'
    Put the IP in a browser address, you should get a page displayed: "Welcome to nginx!".
  2. To ensure that Nginx will be up after reboots:
sudo update-rc.d nginx defaults
  1. Config Nginx on file: /etc/nginx/sites-available/default:

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to index.html
                #try_files $uri $uri/ /index.html;
                proxy_pass http://127.0.0.1:8000;
                access_log off;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }

        location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$ {
                root   /var/www/wawahua/public;
        }
  1. Restart Nginx to reload configuration:
sudo service nginx restart

Reference:

[1]. https://www.digitalocean.com/community/articles/how-to-install-nginx-on-ubuntu-12-04-lts-precise-pangolin
[2]. http://blog.argteam.com/coding/hardening-node-js-for-production-part-2-using-nginx-to-avoid-node-js-load/

⚠️ **GitHub.com Fallback** ⚠️