2

nginx をインストールしたばかりで、複数のドメイン名が同じ IP を指しています。各ドメインを呼び出すとき、同じマシンで実行されている別のアプリケーションにリダイレクトする必要があります。各アプリケーションは別のポートで実行されています。

たとえば、私はapp1.domain.com, app2.domain.com&を持っていますapp3.domain.com

したがって、 同様にapp1.domain.comリダイレクトする必要があるため、リダイレクトする必要があり、リダイレクトする必要が ありますlocalhost:<port1>app2.domain.comlocalhost:<port2>app3.domain.comlocalhost:<port3>

どうすればいいですか?

前もって感謝します

4

1 に答える 1

5

アプリケーションが異なるポートで実行されている場合、nginx conf ファイルは次のようになります。

upstream app1  {
      server 127.0.0.1:port1; #App1
}

upstream app2  {
      server 127.0.0.1:port2; #app2
}

server {
    listen       xxx.xxx.xxx.xxx:80;
    server_name  app1.domain.com;

    access_log  /var/log/nginx/log/app1.domain.com.access.log  main;
    error_log  /var/log/nginx/log/app1.domain.com.error.log;
    root   /usr/share/nginx/html;
    index  index.html index.htm;

    ## send request back to apache1 ##
    location / {
    proxy_pass  http://app1;
    proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
    proxy_redirect off;
    proxy_buffering off;
    proxy_set_header        Host            $host;
    proxy_set_header        X-Real-IP       $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
   }
}

server {
   listen      xxx.xxx.xxx.xxx:80;
   server_name app2.domain.com;
   access_log  /var/log/nginx/log/app2.domain.com.access.log  main;
   error_log   /var/log/nginx/log/app2.domain.com.error.log;
   root        /usr/local/nginx/html;
   index       index.html;

   location / {
        proxy_pass  http://app2;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503         http_504;
        proxy_redirect off;
        proxy_buffering off;
        proxy_set_header        Host            app2.domain.com;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

ご不明な点がございましたら、お知らせください。ありがとう

于 2013-03-13T18:45:55.623 に答える