nginx 配置反向代理根目录到其他服务器

本文介绍了如何通过nginx配置反向代理,将网站的/detail/json路径映射到另一台服务器的/index.html,并在192.168.1.2上处理请求。同时,详细解释了配置中的各个参数,如proxy_pass、proxy_set_header等,确保正确转发请求和设置HTTP头。当192.168.1.2服务器上资源不存在时,会尝试通过try_files指令查找/lvpai/ware路径下的资源。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

location /detail/json {
if ( $uri = "/detail/json" ) {
rewrite "/detail/json" /index.html break;
}
alias /data/web/static_test/detail/json/$host/;
proxy_pass http://192.168.1.2;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
index index.html;
default_type application/json;
proxy_redirect off;
proxy_intercept_errors on;
error_page 403 404 = @index;

location /lvpai/ware {
proxy_pass http://192.1.1.2:9997;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

location @index {
try_files $uri /lvpai/ware/$uri;
}

解读:在1.1上面配置nginx 把根路径配置在1.2上面

如果访问的地址是http://域名/detail/json/xx  实际上获取的资源是1.2相应的路径下的资源

如果1.2下不存在要访问的资源,然后去找try_files

 

转载于:https://www.cnblogs.com/guniang/p/10932447.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值