最近需要转发一些被墙但是又无害的数据, 然后发现转发的数据里面(是个配置文件)还有别的被墙的域名, 所以这时候就需要用到
nginx
的sub_filter
来进行替换了, 然而发现...好像没什么用...
问题
主要问题还是因为gzip的关系, 大部分网站传输数据的时候都进行了gzip压缩, 这就导致sub_filter
无法处理gzip数据最后替换失败了...
解决方案
既然gzip无法替换, 那解压缩后再替换不就好了吗?
server
{
listen 80;
listen 443 ssl http2;
server_name raw.githubusercontent.cc;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/raw.githubusercontent.cc;
ssl_certificate /www/server/panel/vhost/cert/raw.githubusercontent.cc/fullchain.pem;
ssl_certificate_key /www/server/panel/vhost/cert/raw.githubusercontent.cc/privkey.pem;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
add_header Strict-Transport-Security "max-age=31536000";
error_page 497 https://$host$request_uri;
location /go/ {
# 负责解压缩内容
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host raw.githubusercontent.com; #目标域名
proxy_redirect off;
proxy_http_version 1.1;
proxy_buffering off;
proxy_pass https://raw.githubusercontent.com/; #目标域名
}
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host raw.githubusercontent.cc; #自己的域名
proxy_redirect off;
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Accept-Encoding '';
gzip off;
sub_filter_types *; #替换所有类型
sub_filter '//github.com' '//github.xiaoc.cn'; #替换内容
sub_filter '//raw.githubusercontent.com' #替换内容 '//raw.githubusercontent.cc';
sub_filter_once off; #所有匹配到的都替换
proxy_pass http://127.0.0.1/go/; #多走一次转发, 让/go先解压缩gzip
}
access_log /www/wwwlogs/raw.githubusercontent.cc.log;
error_log /www/wwwlogs/raw.githubusercontent.cc.error.log;
}
你好,请教一下/go是怎样实现解压的。
解压什么?zip?还是rar? 不同压缩包格式不同,得用不同的工具才行