[英]Nginx subdomain configuration is wrong
我想将我的Nginx版本1.10.2配置为托管在CentOS 7 OS中的反向代理。 我在同一WildFly 10服务器上运行了几个应用程序。 这些应用程序位于http://213.xxx.xxx.xxx/app1
和http://213.xxx.xxx.xxx/app2
。 我为app2 http://app2.example.com
创建了一个子域。 我的nginx.conf
文件包含以下服务器:
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;
}
}
在Web浏览器中,我可以通过URL example.com
到达app1。 但我无法到达app2。 当我向app2.example.com
发送请求时,它会将我重定向到app2.example.com/app2
。 有人可以告诉我我的配置出了什么问题吗?
好像您是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/;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.