nginx 代理去掉#_Nginx proxy_pass详解

"本文探讨了Nginx代理配置中`proxy_pass`指令对URL路径的影响。示例展示了不同配置下,请求如何被重定向到后端服务器,并分析了日志记录。结论指出,配置末尾是否包含"/"将决定是否保留原始路径。建议始终在`proxy_pass`后使用"/"以确保正确处理路径。"
摘要由CSDN通过智能技术生成

假设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/;)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值