我想配置我的Nginx版本1.10.2作为托管在CentOS 7操作系统中的反向代理。我有几个应用程序在相同的WildFly 10服务器上运行。这些应用程序可在http://213.xxx.xxx.xxx/app1
和http://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
。有人能告诉我配置有什么问题吗?
如果你使用'app1.example.com',会发生同样的事情吗? –
我没有app1的子域,但它与app3一样。 – cheb1k4
我的意思是你可以改变'proxy_pass http://213.xxx.xxx.xxx/app1;';并看看'app2.example.com'加载'app1'好 –