a.com是要被反代理的域名。b.com是当前反代理域名
下面是b.com反代理配置文件
location ~* \.(gif|png|jpg|jpeg|css|js|woff|woff2)$ {
proxy_pass https://www.liyuxiangxs.cc;
proxy_set_header Host www.liyuxiangxs.cc;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
expires 12h;
}
location / {
proxy_set_header X-Proxy-Request true;
proxy_pass https://www.a.com;
proxy_set_header Host www.a.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
add_header X-Cache $upstream_cache_status;
proxy_set_header Accept-Encoding "";
sub_filter "a.com" "b.com";
sub_filter_once off;
add_header Cache-Control no-cache;
}
location ~ ^/(.*)/$ {
rewrite ^/(.*)/$ https://www.a.com/$1/ permanent;
}
a.com配置文件
location / {
if ($http_x_proxy_request != "true") {
#return 301 https://www.b.com$request_uri; #全站301到 b
rewrite ^/(.*)/([0-9]+)\.html$ https://www.b.com/$1/$2.html permanent; #301跳转到指定目录地址
}
}
最后更新时间: