nginx 重写与 Swagger 主体重叠

nginx 重写与 Swagger 主体重叠

这是我的nginx.conf

server {
    charset utf-8;
    client_max_body_size 512M;
    listen 80;
    listen 443 ssl http2 default_server;
    server_name app;

    set $base_root /app;
    root $base_root;

    ssl_certificate /etc/nginx/ssl/nginx-selfsigned.crt;
    ssl_certificate_key /etc/nginx/ssl/nginx-selfsigned.key;
    
    error_log /var/log/nginx/error.log warn;
    access_log /var/log/nginx/access.log main;
    
    index index.php index.html index.htm;

    location ~ api/v(\d+) {
        root $base_root/v$1/web;
        try_files $uri $uri/ /v$1/web/index.php$is_args$args;

        location ~ ^/assets/.+\.php(/|$) {
            deny all;
        }
    }

    location /test {
        root $base_root/documentation;
        try_files $uri $uri/ /documentation/api.php$is_args$args;

    }

    location /swagger {
        root $base_root/documentation;
        try_files $uri $uri/ /documentation/index.php$is_args$args;
    }

    location /admin {
        alias $base_root/backend/web/;

        # prevent the directory redirect to the URL with a trailing slash
        location = /admin {
            # if your location is "/backend", try use "/backend/backend/web/index.php$is_args$args"
            # bug ticket: https://trac.nginx.org/nginx/ticket/97
            try_files $uri /backend/web/index.php$is_args$args;
        }

        # if your location is "/backend", try use "/backend/backend/web/index.php$is_args$args"
        # bug ticket: https://trac.nginx.org/nginx/ticket/97
        try_files $uri $uri/ /backend/web/index.php$args;

        location ~ ^/assets/.+\.php(/|$) {
            deny all;
        }
    }

  

    location ~ ^/.+\.php(/|$) {
        rewrite (?!^/documentation/api.php)$ /documentation/api.php break;
        rewrite (?!^/((backend|v(\d+))/web|admin))^ /backend/web$uri break;
        rewrite (?!^/backend/web)^/admin(/.+)$ /backend/web$1 break;
        rewrite (?!^/v(\d+)/web)^/admin(/.+)$ /v(\d+)/web/index.php?r=$1 break;

        fastcgi_pass 127.0.0.1:9000; # proxy requests to a TCP socket
        #fastcgi_pass unix:/var/run/php-fpm.sock; # proxy requests to a UNIX domain socket (check your www.conf file)
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        include /etc/nginx/fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #try_files $fastcgi_script_name =404;
        #try_files $uri =404;
    }

    # location ~ /\. {
    #     deny all;
    # }
}

我打过这些电话:

http://localhost:8202/swagger/--> 工作顺利

http://localhost:8202/test/--> 工作顺利

http://localhost:8202/api/v1/connect--> 返回与 swagger body 文件相同的内容/test

如何修复这种重叠?是否有一些文档可以了解重写规则如何重叠?

相关内容