【问题标题】:Nginx subdomain configuration is wrongNginx子域配置错误
【发布时间】:2017-08-31 15:46:29
【问题描述】:

我想将我的 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 文件包含这些服务器:

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,它可以工作。

标签: nginx nginx-reverse-proxy


【解决方案1】:

似乎您是应用程序进行重定向,这就是为什么 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/;
    }
}

【讨论】:

  • 还是一样的结果。
  • 你可以使用我在本文中列出的方法进行调试吗? tarunlalwani.com/post/…。使用详细信息在问题中发布更多详细信息
猜你喜欢
  • 2012-04-11
  • 2018-12-19
  • 2013-07-08
  • 2013-12-04
  • 2018-12-22
  • 2016-02-04
  • 2016-08-23
  • 2019-04-09
  • 1970-01-01
相关资源
最近更新 更多