2017-08-30 64 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/。在问题中提供更多详细信息 –