Nginx rewrite 到其他域名不301或302跳转方法
Nginx rewrite 到外网URL不301或302跳转方法
Nginx默认rewrite在有http的时候会自动301或者302跳转到新的URL,没有http的时候则不会跳转.
抓住Nginx rewrite的这个特点则有办法解决 rewrite 到外网URL域名跳转的方法
1.在 Nginx 虚拟主机中创建个 proxy_pass
location /request-service/ {
proxy_pass http://10.140.12.1:8088/;
proxy_read_timeout 90;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
}
2.配置域名重写加上面的 proxy_pass location 的虚拟路径
rewrite /api/v1/request/test /request-service/api/v1/request/test;