简体   繁体   English

Nginx子域配置错误

[英]Nginx subdomain configuration is wrong

I would like to configure my Nginx version 1.10.2 as a reverse proxy hosted in a CentOS 7 OS. 我想将我的Nginx版本1.10.2配置为托管在CentOS 7 OS中的反向代理。 I have several applications running on the same WildFly 10 server. 我在同一WildFly 10服务器上运行了几个应用程序。 Those applications are available at http://213.xxx.xxx.xxx/app1 and http://213.xxx.xxx.xxx/app2 . 这些应用程序位于http://213.xxx.xxx.xxx/app1http://213.xxx.xxx.xxx/app2 I created a subdomain for app2 http://app2.example.com . 我为app2 http://app2.example.com创建了一个子域。 My nginx.conf file contains those servers: 我的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;
    }
}

From my web browser I can reach app1 at URL example.com . 在Web浏览器中,我可以通过URL example.com到达app1。 But I can't reach app2. 但我无法到达app2。 When I send a request to app2.example.com , it redirects me to app2.example.com/app2 . 当我向app2.example.com发送请求时,它会将我重定向到app2.example.com/app2 Can someone tells me what is wrong with my configuration? 有人可以告诉我我的配置出了什么问题吗?

Seems like you are app does the redirects and that is why app1 works and app2 doesn't work. 好像您是app一样执行重定向,这就是为什么app1起作用而app2不起作用的原因。 Now there are few things you can try 现在,您可以尝试几件事

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM