YApi Nginx 二级目录反代 gzip sub_filter

需要进行两次反代,虽然只进行一次反代并替换文本也会有效果,但页面会空白和报错,应该是受到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_filter)