2016-02-10 229 views
1

我需要:nginx的反向代理環

  1. 點site.com我site.github.io(的作品)
  2. 點site.com/anything文件系統/現場/ DIST(即作品)
  3. 點site2.com到site.com文件系統/根/ DIST(不工作,此處顯示site.github.io)

site.com.conf

server { 
    listen 80; 
    server_name site.com; 

    location =/{ 
     proxy_pass    http://site.github.io; 
     proxy_set_header  Host     $host; 
     proxy_set_header  X-Forwarded-For   $remote_addr; 
    } 

    location/{ 
     root /site/dist; 
     try_files $uri /index.html; 
    } 
} 

site2.com.conf

server { 
    listen 80; 
    server_name site2.com; 

    proxy_set_header Host site.com; 
    proxy_set_header X-Forwarded-For $remote_addr; 

    location/{ 
     proxy_pass http://127.0.0.1/$request_uri; 
    } 

} 

回答

1

在你要與URI來結束的情況下http://site2.com = 「/」 打黑site.com,您已設置爲代理site.github時。 IO。

你可能想要做的,而不是爲站點2是:

location/{ 
    proxy_pass http://127.0.0.1/site2/$request_uri; 
} 
在site.com

然後:

location ~ ^/site2(.*)$ { 
    root /site/dist; 
    try_files $1 /index.html; 
} 

OR

location /site2 { 
    rewrite ^/site2(.*)$ $1 break; 
    root /site/dist; 
    try_files $uri /index.html; 
}