동일한 Apache 서버에서 다른 도메인에 대한 LB로 "serverpool"을 사용하는 NGINX?

동일한 Apache 서버에서 다른 도메인에 대한 LB로 "serverpool"을 사용하는 NGINX?

나는 LB로 nginx를 가지고 있습니다. 그리고 2개의 Apache가 웹 서버로 사용됩니다. 내가 다른 도메인을 가지고 있다고 가정해 보겠습니다.

  • www.example.com
  • checkout.example.com

두 도메인 모두 동일한 2개의 Apache 서버에 있습니다. 하지만 ofcoz는 다른 디렉토리에 있습니다. 그리고 VHostApache vhost 파일의 다른 파일을 사용합니다 .

아래 디자인과 같습니다.

          Nginx
            |
      -------------
      |           |
   Apache       Apache

다음은 두 번째 도메인(checkout.example.com)에서 작동하지 않는 현재 기존 Nginx .conf 파일입니다.

NGINX(mysites.conf)에서:

upstream serverpool {
  server 1.2.3.101:80 weight=1;
  server 1.2.3.102:80 weight=1;
}

server {
  listen 80;
  server_name www.example.com checkout.example.com;
  location / {
    proxy_pass http://serverpool;
  }
}

2개의 Apache 서버 모두에서같은Vhost 파일(httpd.conf):

<VirtualHost *:80>
   ServerName www.example.com
   DocumentRoot /var/www/html/www.example.com/
</VirtualHost>
<VirtualHost *:80>
   ServerName checkout.example.com
   DocumentRoot /var/www/html/checkout.example.com/
</VirtualHost>

하지만 내가 그걸 찾아볼 때마다 (http://checkout.example.com),도메인이 계속 표시됩니다.브라우저에서 ..하지만 (www.example.com)의 내용으로, 완전히 잘못된 것입니다.

내가 뭘 잘못했나요?

답변1

거의 항상 헤더를 설정해야 합니다 Host. 그렇지 않으면 nginx는 기본값으로 돌아가며 proxy_set_header Host $proxy_host;귀하의 경우에는 serverpool아파치에 쓸모가 없습니다.

보다http://nginx.org/r/proxy_set_header그리고http://nginx.org/r/proxy_pass자세한 내용은.

upstream serverpool {
  server 1.2.3.101:80 weight=1;
  server 1.2.3.102:80 weight=1;
}

server {
  listen 80;
  server_name www.example.com checkout.example.com;
  location / {
    proxy_pass http://serverpool;
    proxy_set_header Host $host;
  }
}

답변2

HOST: 헤더를 업스트림 서버 IP로 보내야 합니다.

이 기사는 질문에 완전히 대답하고 있습니다.

역방향 프록시를 수행할 때 nginx가 업스트림의 호스트 이름을 전달하도록 만듭니다.

또한 nginx 구성은 다음과 같아야합니다

    upstream serverpool {
  server 1.2.3.101:80 weight=1;
  server 1.2.3.102:80 weight=1;
}

server {
  listen 80;
  server_name www.example.com checkout.example.com;
  location / {
    proxy_pass http://serverpool;
    proxy_set_header Host $host;
  }
}

관련 정보