Nginx把网站反代到二级目录
军哥lnmp,自建一个conf,把www.bbb.com反代到www.aaa.com/bbb/
server {
listen 80;
server_name www.aaa.com;
location ^~ /bbb {
#配合subs_filter替换字段。
#subs_filter_types text/css text/xml;
#subs_filter ‘”/?’ ‘”/bbb/?’ gi;
#subs_filter ‘”/Skin/’ ‘”/bbb/Skin/’ gi;
#subs_filter ‘/css/’ ‘/bbb/css/’ gi;
#subs_filter ‘”/images/’ ‘”/bbb/images/’ gi;
#subs_filter ‘”/Up/’ ‘”/bbb/Up/’ gi;
#替换模块,下文详解。
proxy_cache_key “$scheme://$host$request_uri”;
#缓存key规则,用于自动清除缓存。
proxy_cache cache_one;
#缓存区名称,必须与前面定义的相同
proxy_cache_valid 200 304 3h;
proxy_cache_valid 301 3d;
proxy_cache_valid any 10s;
#200 304状态缓存3小时
#301状态缓存3天
#其他状态缓存(如502 404)10秒
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#向后端传递访客ip
proxy_set_header Referer http://www.bbb.com;
#强制定义Referer,程序验证判断会用到
proxy_set_header Host www.bbb.com;
#定义主机头
proxy_pass http://www.bbb.com/;
#指定后端ip,可用末尾带斜杠的网址代替
proxy_set_header Accept-Encoding “”;
#清除编码,针对启用zip压缩的网站
proxy_cache_use_stale invalid_header error timeout http_502;
#当后端出现错误、超时、502状态时启用过期缓存
}
启用缓存参考
http://huangshanben.com/articles/2900/
Subs_filter模块使用方法参考
https://github.com/yaoweibin/ngx_http_substitutions_filter_module
via.https://www.suxilog.com/%E5%8F%8D%E4%BB%A3/nginx%E6%8A%8A%E7%BD%91%E7%AB%99%E5%8F%8D%E4%BB%A3%E5%88%B0%E4%BA%8C%E7%BA%A7%E7%9B%AE%E5%BD%95.html