Skip to content

Instantly share code, notes, and snippets.

@dipanshuchaubey
Created March 5, 2020 14:50
Show Gist options
  • Save dipanshuchaubey/be345c7e02e5a3a91cc17ddcc456c2b4 to your computer and use it in GitHub Desktop.
Save dipanshuchaubey/be345c7e02e5a3a91cc17ddcc456c2b4 to your computer and use it in GitHub Desktop.
Nginx Reverse Proxy

Nginx Reverse Proxy

Unlink default configs

First, unlink the default configuration which shows Nginx Welcome page on port 80 using the command

path /etc/nginx/sites-enabled

$ sudo unlink default

Add new configs

Create a new .conf file with reverse proxy configuration

path /etc/nginx/conf.d

$ sudo nano sites.conf

Use the following config for each reverse proxy that you want to apply

server {
   listen 80 default_server;
   server_name yourdomain.com www.yourdomain.com;

   location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_pass http://localhost:3000;
   }

}

server {
   listen 80;
   server_name yourdomain.in www.yourdomain.in;

   location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_pass http://localhost:5000;
   }
}

Save Configurations

Now, test your configurations using:

$ sudo nginx -t

Check nginx status to verify that everything is working properly

$ sudo systemctl status nginx

Restart the server to apply changes using:

$ sudo systemctl restart nginx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment