nginx 反向代理循环

nginx reverse proxy loop

我需要:

  1. 将 site.com 指向我的 site.github.io(有效)
  2. 将站点 com/anything 指向文件系统 /site/dist(有效)
  3. 指向site2.com到site.com到文件系统/root/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;
    }

}

http://site2.com 的情况下,您将在点击 site.com 时以 uri = "/" 结束,您已将其设置为 site.github.io 的代理。

您可能想为 site2 做的是:

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

然后在site.com:

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

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