sub_filter 'www_servers:80/DaChui/' 'www.xxx.com/';
           sub_filter 'http://www_servers:80/DaChui/' 'http://www.xxx.com/';
           sub_filter 'http://www_servers/DaChui/' 'http://www.xxx.com/';
           sub_filter_once off;

在nginx中配置proxy_pass代理转发时,如果在proxy_pass后面的url加/,表示绝对根路径;如果没有/,表示相对路径,
把匹配的路径部分也给代理走。

代理非80端口问题 需要添加 proxy_set_header Host $host:$server_port
upstream falcon {
        server 172.31.20.205:8010;
}
location / {
            proxy_pass http://falcon/;
            proxy_set_header Host $host:$server_port;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

假设下面四种情况分别用 http://192.168.1.1/proxy/test.html 进行访问。


第一种:
location /proxy/ {
    proxy_pass http://127.0.0.1/;
}
代理到URL:http://127.0.0.1/test.html


第二种(相对于第一种,最后少一个 / )
location /proxy/ {
    proxy_pass http://127.0.0.1;
}
代理到URL:http://127.0.0.1/proxy/test.html


第三种:
location /proxy/ {
    proxy_pass http://127.0.0.1/aaa/;
}
代理到URL:http://127.0.0.1/aaa/test.html


第四种(相对于第三种,最后少一个 / )
location /proxy/ {
    proxy_pass http://127.0.0.1/aaa;
}
代理到URL:http://127.0.0.1/aaatest.html

results matching ""

    No results matching ""