nginx 反代的sub_filter替换无效

标签: 

正在查看 7 个帖子:1-6 (共 6 个帖子)
  • 作者
    帖子
  • normedia
    • 文章数量: 4
    @normedia
    楼主

    123.com反代abc.com

    abc.com/123.json 可以替换成功
    abc.com/456.abc.js 替换无效需求是要解决456.abc.js的替换问题

    proxy_set_header Accept-Encoding “”;

    sub_filter_types *;

    sub_filter_once off;

    这些都写了

    求解决这个问题,付费求助,加616+764+47=Q

    来自杭州, 浙江省, 中国
    孙锡源
    • 文章数量: 704
    @ibadboy

    把你完整的nginx配置文件贴上来。论坛编辑器有贴代码功能

    来自张家口市, 河北省, 中国
    normedia
    • 文章数量: 4
    @normedia
    楼主
    #PROXY-START/
    location ~* .(gif|png|jpg|css|js|woff|woff2)$
    {
           proxy_pass https://cmsstaticv2.ffquan.cn;
        proxy_set_header Host cmsstaticv2.ffquan.cn;
        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_pass https://cmsstaticv2.ffquan.cn;
        proxy_set_header Host cmsstaticv2.ffquan.cn;
        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;
        
        #Set Nginx Cache
           
    
    
    
       	sub_filter_types *;
    
           proxy_set_header Accept-Encoding "";    
    
        sub_filter "ffquan" "xiaoke";
        
        sub_filter_once off;
        	add_header Cache-Control no-cache;
    }
    
    #PROXY-END/

    https://fandai1.xiaoke.name/asset-manifest.json

    可以替换成功

    https://fandai1.xiaoke.name/js/app.591f9646.js

    替换无效

    来自杭州, 浙江省, 中国
    孙锡源
    • 文章数量: 704
    @ibadboy

    location 匹配的原则是从长到短,所以你上面的配置文件中 app.591f9646.js 匹配到的是以下块:

    location ~* .(gif|png|jpg|css|js|woff|woff2)$
    {
        proxy_pass https://cmsstaticv2.ffquan.cn;
        proxy_set_header Host cmsstaticv2.ffquan.cn;
        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;
    }

    想对关键字替换的话就把替换相关的配置提升到全局作用域上

    来自张家口市, 河北省, 中国
    normedia
    • 文章数量: 4
    @normedia
    楼主
    #PROXY-START/
    
    location /
    {
        proxy_pass https://cmsstaticv2.ffquan.cn;
        proxy_set_header Host cmsstaticv2.ffquan.cn;
        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;
        
        #Set Nginx Cache
           
    
       	sub_filter_types *;
    
           proxy_set_header Accept-Encoding "";    
    
        sub_filter "ffquan" "xiaoke";
        
        sub_filter_once off;
        	add_header Cache-Control no-cache;
    }
    
    #PROXY-END/
    #PROXY-START/
    location ~* .(gif|png|jpg|css|js|woff|woff2)$
    {
        proxy_pass https://cmsstaticv2.ffquan.cn;
        proxy_set_header Host cmsstaticv2.ffquan.cn;
        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;
        
        sub_filter_types *;
        proxy_set_header Accept-Encoding "";    
        sub_filter "ffquan" "xiaoke";
        sub_filter_once off;
    }
    location /
    {
        proxy_pass https://cmsstaticv2.ffquan.cn;
        proxy_set_header Host cmsstaticv2.ffquan.cn;
        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;
        
        #Set Nginx Cache
           
    
        sub_filter_types *;
    
        proxy_set_header Accept-Encoding "";    
    
        sub_filter "ffquan" "xiaoke";
        
        sub_filter_once off;
        add_header Cache-Control no-cache;
    }
    
    #PROXY-END/

    改成这2段还是无效啊

    来自杭州, 浙江省, 中国
    孙锡源
    • 文章数量: 704
    @ibadboy

    我测试看已经生效了。你 ctrl+f5 刷新看看,或者在 url 后面追加个随机参数

    来自张家口市, 河北省, 中国
    normedia
    • 文章数量: 4
    @normedia
    楼主

    缓存这个坑,刚都换浏览器测试了……

    来自杭州, 浙江省, 中国
正在查看 7 个帖子:1-6 (共 6 个帖子)
  • 哎呀,回复话题必需登录。

话题信息