问题
主要问题还是因为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/; #目标域名 proxy_set_header Accept-Encoding 'gzip'; gunzip on; } location / { proxy_pass http://127.0.0.1/go/; #多走一次转发, 让/go先解压缩gzip 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; #所有匹配到的都替换 } access_log /www/wwwlogs/raw.githubusercontent.cc.log; error_log /www/wwwlogs/raw.githubusercontent.cc.error.log; }