2017-08-30 91 views
0

我想配置我的Nginx版本1.10.2作爲託管在CentOS 7操作系統中的反向代理。我有幾個應用程序在相同的WildFly 10服務器上運行。這些應用程序可在http://213.xxx.xxx.xxx/app1http://213.xxx.xxx.xxx/app2。我爲app2 http://app2.example.com創建了一個子域。我nginx.conf文件包含了這些服務器:Nginx的子域配置是錯誤的

server { 
    listen 80; 
    server_name example.com www.example.com; 
    location/{ 
     proxy_pass http://213.xxx.xxx.xxx/app1; 
    } 
} 

server { 
    listen 80; 
    server_name app2.example.com www.app2.example.com; 
    location/{ 
     proxy_set_header X-Forwarded-For $remote_addr; 
     proxy_set_header Host $host; 
     proxy_pass http://213.xxx.xxx.xxx/app2; 
    } 
} 

從我的網頁瀏覽器,我可以在URL example.com達到APP1。但我無法達到app2。當我向app2.example.com發送請求時,它會將我重定向到app2.example.com/app2。有人能告訴我配置有什麼問題嗎?

+0

如果你使用'app1.example.com',會發生同樣的事情嗎? –

+0

我沒有app1的子域,但它與app3一樣。 – cheb1k4

+0

我的意思是你可以改變'proxy_pass http://213.xxx.xxx.xxx/app1;';並看看'app2.example.com'加載'app1'好 –

回答

0

好像你是app是否重定向,這就是爲什麼app1工作,app2不起作用。現在你可以嘗試幾件事

server { 
    listen 80; 
    server_name app2.example.com www.app2.example.com; 
    location/{ 
     proxy_set_header X-Forwarded-For $remote_addr; 
     proxy_set_header Host $host; 
     proxy_pass http://213.xxx.xxx.xxx/app2; 
     proxy_redirect http://213.xxx.xxx.xxx/app2/ http://$host/; 
    } 
} 
+0

仍然是相同的結果。 – cheb1k4

+0

您可以使用本文中列出的方法進行調試嗎? http://tarunlalwani.com/post/how-to-debug-nginx-reverse-proxy-issues-php-fpm-gunicorn-uwsgi/。在問題中提供更多詳細信息 –