# Ngnix Reverse Proxy

  1. Update the APT packet cache and install the Nginx web server via the packet manger:
apt-get update
apt-get install nginx
  1. Disable the default virtual host, that is pre-configured when Nginx is istalled via Ubuntu’s packet manager apt:
unlink /etc/nginx/sites-enabled/default
  1. . Enter the directory /etc/nginx/sites-available and create a reverse proxy configuration file.
cd /etc/nginx/sites-available
nano reverse-proxy.conf
  1. Paste the following Nginx configuration in the text editor.
server {
    server_name XXXXX.brainwise.me ;
    set $upstream 127.0.0.1:5005;

    location /socket.io/ {
         proxy_pass http://$upstream;
         proxy_set_header Upgrade $http_upgrade;
         proxy_set_header Connection "upgrade";
         proxy_set_header Host $host;
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_http_version 1.1;
         proxy_set_header Connection "";
         proxy_buffering off;
         client_max_body_size 0;
         proxy_read_timeout 10000s;
         proxy_redirect off;
     }
     location / {
        proxy_pass http://127.0.0.1:8888;
        proxy_http_version  1.1;
        proxy_cache_bypass  $http_upgrade;

        proxy_set_header Upgrade           $http_upgrade;
        proxy_set_header Connection        "upgrade";
        proxy_set_header Host              $host;
        proxy_set_header X-Real-IP         $remote_addr;
        proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host  $host;
        proxy_set_header X-Forwarded-Port  $server_port;
  }
}

TIP

Accesses and errors are located in a log files at /var/log/nginx.

  1. Copy the configuration from /etc/nginx/sites-available to /etc/nginx/sites-enabled . It is recommended to use a symbolic link.
ln -s /etc/nginx/sites-available/reverse-proxy.conf /etc/nginx/sites-enabled/reverse-proxy.conf
  1. Test the Nginx configuration file
nginx -t

which returns

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

  1. Open a web browser on your local computer and paste your public_ip which will display your web applications homepage