Nginx serves root of one subdomain instead of root

2019-08-27 17:09发布

I have two subdomains, app.mydomain.com and v1.api.mydomain.com, pointing to the same IP. I want app.mydomain.com to be proxied to localhost:5000 and v1.api.mydomain.com to be proxied to localhost:1337.

The following configuration does it (app.mydomain.com/... is served by localhost:5000 and v1.api.mydomain.com/... is served by localhost:1337) except for one thing: the root of v1.api.mydomain.com (with or without a trailing slash) isn't served by localhost:1337, it is served by localhost:5000 (app.mydomain.com) and therefore it doesn't display what I expect. How is this possible?

My first configuration file in sites-enabled:

server {
  listen 80;

  server_name app.mydomain.com;

  location / {
      proxy_pass http://localhost:5000/;
      proxy_http_version 1.1;  
      proxy_set_header Upgrade $http_upgrade;  
      proxy_set_header Connection 'upgrade';  
      proxy_set_header Host $host;  
      proxy_cache_bypass $http_upgrade; 
  }

My second configuration file in site-enabled:

server {
  listen 80;

  server_name v1.api.mydomain.com;

  location / {
      proxy_pass http://localhost:1337/;
      proxy_http_version 1.1;  
      proxy_set_header Upgrade $http_upgrade;  
      proxy_set_header Connection 'upgrade';  
      proxy_set_header Host $host;  
      proxy_cache_bypass $http_upgrade; 
  }
}

To make sure that the problem wasn't a redirection of some sort by the server running on localhost:1337, I shut it down and the problem is still there, so it really is something with my nginx configuration. Thanks for helping.

标签: nginx
0条回答
登录 后发表回答