简体   繁体   中英

Nginx Reverse Proxy with Multiple Backend Domains

I have a 2 servers :-

Server 1 : NGINX Reverse Proxy.

Server 2 : NGINX with 5-6 websites ( different domains )

So basically, all users will come to Server 1 which will proxy_pass the traffic to Server 2 and get the response back. Server 1 will also do Caching, WAF etc.

Here is my configuration for Server 1 :-

server {
  listen 80;
  server_name example.com www.example.com;

  location ~* {
     proxy_pass http://mysite:80;
}
}

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

  location ~* {
     proxy_pass http://mysite:80;
}
}

In my Server 2, in virtual.conf of NGINX, i have the following config :

index index.php index.html;
server {
    listen   80;
    server_name  example.com www.example.com;

    location / {
        root   /var/www/websites/example/;
        include location-php;
    }
}

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

        location / {
            root   /var/www/websites/server/;
            include location-php;
        }
    }

However whenever i go to http://example.com or http://server.com ( directed via Sever 1 acting as Reverse Proxy ), it shows the Server 2's Default NGINX Page. I am not sure what am I doing wrong. Also is this type of setup a proper way of doing things ?

This is your host problem.
Due to your upstream name is mysite , so the host name in upstream request is mysqsite too.
So the host isn't matched by the backend servers.

You can solve the problem like this by adding the directive before proxy_pass :
proxy_set_header Host server.com

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM