Home > Net >  Nginx Reverse Proxy: Proxying 2 different servers with using 1 server
Nginx Reverse Proxy: Proxying 2 different servers with using 1 server

Time:04-23

I have 1 Nginx proxy server but I have 2 different normal server. I want to proxying this normal server using just 1 nginx proxy server. It may be simple but I couldn't find it anywhere.

Here my code in /etc/nginx/sites-available/default (With this code I can proxy just 1 server):

server {
    listen       80;   
    #server_name 1ndwebsite.com;
    root         /usr/share/nginx/html;

       location / {
          proxy_redirect      off;
          proxy_set_header    X-Real-IP $remote_addr;
          proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header    Host $http_host;
          proxy_pass          https://122.122.122.123;
    }
}

I tried this for 2nd server but it didn't work.

server {
    listen       80;   
    #server_name 1ndwebsite.com;
    root         /usr/share/nginx/html;

       location / {
          proxy_redirect      off;
          proxy_set_header    X-Real-IP $remote_addr;
          proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header    Host $http_host;
          proxy_pass          https://122.122.122.123;
    }
}
server {
    listen       80;   
    #server_name 2ndwebsite.com;
    root         /usr/share/nginx/html;

       location / {
          proxy_redirect      off;
          proxy_set_header    X-Real-IP $remote_addr;
          proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header    Host $http_host;
          proxy_pass          https://211.211.211.213;
    }
}

CodePudding user response:

So interesting but I solve this issue with add include /etc/nginx/proxy_params; after the location tag.

  • Related