简体   繁体   中英

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. I have several applications running on the same WildFly 10 server. Those applications are available at http://213.xxx.xxx.xxx/app1 and http://213.xxx.xxx.xxx/app2 . I created a subdomain for app2 http://app2.example.com . My nginx.conf file contains those servers:

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 . But I can't reach app2. When I send a request to app2.example.com , it redirects me to 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. 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/;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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