nginx反向代理循环

时间:2016-02-10 21:59:23

标签: nginx reverse-proxy

我需要:

  1. 指向site.com到我的site.github.io(有效)
  2. 指向siteystem / site / dist(有效)
  3. 将site2.com指向site.com到filesystem / root / dist(不起作用,此处显示site.github.io)
  4. 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 个答案:

答案 0 :(得分:1)

http://site2.com的情况下,您最终将使用uri =" /"当你点击site.com,你已经设置代理到site.github.io。

您可能希望代替site2:

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;
}