保持url不变,内容来自于另一个域名url的nginx配置
2020-03-04 本文已影响0人
风吹路过的云
需求是这样的,前端开发的同学要求保持url不变,但是内容来自于另一个域名某个url的内容,问nginx该怎么配置
其实就是用反向代理实现
server {
listen 443;
server_name aaa.bbb.com;
index index.html;
# charset koi8-r;
access_log logs/zzz.access.log access;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
root /data/xxx/views/ccc;
expires -1;
####################################
# proxy_pass实现了,关键是 proxy_set_header
####################################
location /bb/lib/ {
proxy_set_header Host static.yyy.com;
proxy_pass https://static.yyy.com/static/bb/lib/;
}
#############################
# rewrite也可以转换,但url变了
#########################
#if ($uri ~* /bb/lib) {
# rewrite ^(.*) https://static.yyy.com/static$1 permanent;
#}
}
参考资料
https://serverfault.com/questions/396595/nginx-proxy-domain-to-another-domain-with-no-change-url