nginx反向代理循环

nginx反向代理循环,nginx,reverse-proxy,Nginx,Reverse Proxy,我需要: 将site.com指向my site.github.io(有效) 将site.com/anything指向filesystem/site/dist(可以正常工作) 将site2.com指向site.com指向filesystem/root/dist(这不起作用,这里显示的是site.github.io) site.com.conf server { listen 80; server_name site.com; location = / {

我需要:

  • 将site.com指向my site.github.io(有效)
  • 将site.com/anything指向filesystem/site/dist(可以正常工作)
  • 将site2.com指向site.com指向filesystem/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;
        }
    
    }
    
    在这种情况下,当点击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 $1 /index.html;
    }
    

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