美文网首页
YApi Nginx 二级目录反代 gzip sub_filte

YApi Nginx 二级目录反代 gzip sub_filte

作者: 此昵称已被狗抢占 | 来源:发表于2021-10-15 20:32 被阅读0次

    需要进行两次反代,虽然只进行一次反代并替换文本也会有效果,但页面会空白和报错,应该是受到YApi nodejs后台的gzip压缩影响

        location /yapi_forward/ {
            proxy_pass http://127.0.0.1:3000/;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
            proxy_http_version 1.1;
            proxy_set_header Accept-Encoding 'gzip';
            gunzip on;
        }
    
        location /yapi/ {
            proxy_pass https://yourdomain.com/yapi_forward/;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
            proxy_http_version 1.1;
            proxy_set_header Accept-Encoding "";
            sub_filter '"/prd' '"/yapi/prd';
            sub_filter '"/iconfont' '"/yapi/iconfont';
            sub_filter '"/image' '"/yapi/image';
            sub_filter '"/api' '"/yapi/api';
            sub_filter '"/user' '"/yapi/user';
            sub_filter '"/group' '"/yapi/group';
            sub_filter '"/project' '"/yapi/project';   
            sub_filter '"/mock' '"/yapi/mock';
            sub_filter 'path:"/' 'path:"/yapi/';
            sub_filter 'to:"/' 'to:"/yapi/';
            sub_filter 'history.push("/' 'history.push("/yapi/';
            sub_filter_types *;
            sub_filter_once off;
        }
    

    进行两次反代替换gzip文本内容最简单的例子

    location /forward {
        proxy_pass https://example.com;
        proxy_set_header Accept-Encoding 'gzip';
        gunzip on;
    }
    
    location / {
        proxy_pass https://yourdomain.com/forward;
        proxy_set_header Accept-Encoding '';
    
        sub_filter_types *;
        sub_filter_once off;
        sub_filter 'example.com' 'yourdomain.com';
    }
    

    参考了以下内容
    https://github.com/YMFE/yapi/issues/1431
    https://www.app-scope.com/tutorial/force-nginx-to-decompress-gzipped-request.html

    相关文章

      网友评论

          本文标题:YApi Nginx 二级目录反代 gzip sub_filte

          本文链接:https://www.haomeiwen.com/subject/aezmoltx.html