nginx 跳转配置
示例1:需求:wiki.test.com/api-wm/* 的请求代理转发到 wm.test.com/api-wm/*
配置方法:
方法一(采用的是这个):
location /api-wm/ {
set $upstream_name "vm.test.com的appkey";
proxy_pass http://$upstream_name;
}
方法二:
location /api-vm/ {
rewrite ^(.*)$ https://vm.test.com/api-vm/$1 permanent;
}
示例2
配置nginx rewrite跳转的时候(或类似场景),能适用变量的尽量使用变量,不要写固定的域名
不规范的配置示例:
location /jixiao {
rewrite ^ http://qy.test.com/performance permanent;
}
规范的配置示例:
location /jixiao {
rewrite ^ http://$server_name/performance permanent;
//使用$server_name代替请求中的qy.test.com
}
页:
[1]