NodeJS By Examples

Run NginX as reverse proxy

 Thanks to https://www.digitalocean.com/community/tutorials/how-to-host-multiple-node-js-applications-on-a-single-vps-with-nginx-forever-and-crontab

 

 1. Create nginx config file: /etc/nginx/sites-available/com_find-ads_www.conf

#redirect to www
server {
  server_name find-ads.com;
  return 301 $scheme://www.$host$request_uri;
}


server {

  ############### General Settings ####################
    listen   80;
    server_name  www.find-ads.com;

    root    "/homemiko/com_find-ads/www/public_html/";
  index  index.php index.html;
    charset utf-8;
    #autoindex on;
  error_log "/homemiko/com_find-ads/logs/www_find-ads_com_error.log";
  #access_log "/homemiko/com_find-ads/logs/www_find-ads_com_access.log";

  location / {
      proxy_pass http://localhost:3333;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection 'upgrade';
      proxy_set_header Host $host;

    

#forward client's IP to nodeJS

      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;


      proxy_cache_bypass $http_upgrade;
  }

}

 

 

2. restart nginX

#service nginx restart