通过nginx做为反向代理,将yapi反向代理到二级目录上。

需要通过再次代理来实现。

nginx配置文件如下:

server {
    listen       80;
    server_name  yourdomain.com;

    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 http://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;
    }
}