假设server_name为www.test.com
当请求URL为http://www.test.com/zabbix/index.html时,以下示例的访问结果是
示例1:
location /zabbix/ {
proxy_pass http://192.168.1.10;
}
结果1:http://192.168.1.10/zabbix/index.html
web服务器访问日志:
"GET /zabbix/index.html HTTP/1.0" 200 509
示例2:
location /zabbix/ {
proxy_pass http://192.168.1.10/;
}
结果2:http://192.168.1.10/index.html
web服务器日志:
"GET /index.html HTTP/1.0" 404 555
示例3:
location /zabbix/ {
proxy_pass http://192.168.1.10/linux;
}
结果3:http://192.168.1.10/linuxindex.html
web服务器日志:
"GET /linuxindex.html HTTP/1.0" 404 555
示例4:
location /zabbix/ {
proxy_pass http://192.168.1.10/linux/;
}
结果4:http://192.168.1.10/linux/index.html
web服务器日志:
"GET /linux/index.html HTTP/1.0" 404 555
二、代理服务器配置示例:
server {
listen443 ssl;server_name www.test.com;charset utf-8;
#access_log /var/log/nginx/host.access.log main;ssl_certificate./crt/chain.crt;ssl_certificate_key./crt/key.key;
# location /zabbix/{# proxy_pass http://192.168.1.10;
#}# location /zabbix/{# proxy_pass http://192.168.1.10/;
#}# location /zabbix/{# proxy_pass http://192.168.1.10/linux;
#}
location/zabbix/{
proxy_pass http://192.168.1.10/linux/;}
}
server {
listen80;server_name www..test.com;location/{
rewrite/(.*) https://www.xwupiaomiao.cn/$1 break;}
}
结论:
如果proxy_pass配置值包含"/"就去掉匹配路径部分
如果proxy_pass配置值不包含"/"就保留匹配路径部分
建议所有的proxy_pass后的url都以“/”结尾(proxy_pass http://192.168.1.10/linux/;)