Configure Nginx as Reverse Proxy server

Author: Al-mamun Sarkar Date: 2020-04-14 16:16:00

Configure Nginx as a Reverse Proxy server. The following codes show how to create a reverse proxy server on Nginx.

 

Create a Virtual host which will run on 7001 port:

server {
        listen 7001 default_server;
        index index.html index.htm index.php;
        root /var/www/text;
}

 

Check configuration:

nginx -t

 

Create test folder:

mkdir /var/www/test

Create index.html file inside test folder:

echo "Welcome to test on port 7001" > /var/www/test/index.html

 

Reload Nginx server:

systemctl reload nginx

 

Now you can browse http://127.0.0.1:7001 

 

Now Create a Virtual host for proxy server:

vim /etc/nginx/conf.d/proxy_server.conf

Paste the following codes: 

upstream app_server_7001 {
    server 127.0.0.1:7001;
}

server {
    listen 88;

    location /proxy {
        # Trailing slash is key!
        proxy_pass http://app_server_7001/;
    }
}

 

Check configuration:

nginx -t

 

Reload Nginx Server:

systemctl reload nginx

 

Now you can browse http://127.0.0.1:88/proxy but you will get the content of http://127.0.0.1:7001