【发布时间】:2017-08-31 15:46:29
【问题描述】:
我想将我的 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 文件包含这些服务器:
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 是一样的。
-
我的意思是你能改变
proxy_pass http://213.xxx.xxx.xxx/app1;;看看app2.example.com是否加载app1很好 -
在我的第二个服务器配置中,如果我将
proxy_pass http://213.xxx.xxx.xxx/app2更改为proxy_pass http://213.xxx.xxx.xxx/app1,它可以工作。