Url匹配错误的nginx位置

Url匹配错误的nginx位置,nginx,location,match,Nginx,Location,Match,使用下面的nginx-conf,我似乎无法匹配/api/v2/macs/,而是转到/api/。问题是,我在多个环境中尝试了相同的配置,但仅在我的主生产环境中失败了。有什么想法吗 server { listen 80 default_server; client_max_body_size 0; charset UTF-8; proxy_read_timeout

使用下面的nginx-conf,我似乎无法匹配/api/v2/macs/,而是转到/api/。问题是,我在多个环境中尝试了相同的配置,但仅在我的主生产环境中失败了。有什么想法吗

server {

    listen                      80  default_server;

    client_max_body_size        0;
    charset                     UTF-8;

    proxy_read_timeout          300;
    proxy_intercept_errors      on;

    error_page                  403                         /403;
    error_page                  404                         /404;
    error_page                  502                         /502;

    server_tokens               off;
    add_header                  X-Frame-Options             SAMEORIGIN;

    # Enable Gzip
    gzip                        on;
    gzip_http_version           1.0;
    gzip_comp_level             2;
    gzip_min_length             1100;
    gzip_buffers                4 8k;
    gzip_proxied                any;
    gzip_types
                                # text/html is always compressed by HttpGzipModule
                                text/css
                                text/javascript
                                text/xml
                                text/plain
                                text/x-component
                                application/javascript
                                application/json
                                image/svg+xml;


    # Serve index.html
    location / {
        root                    /usr/share/nginx/html;
        index                   index.html index.htm;
        autoindex               off;
        error_page              404                         /404;
        # Cache busting
        if_modified_since       off;
        expires                 -1;
    }

    location /api/v2/macs/ {
        rewrite                 ^/api/v2/macs/(.*)            /$1             break;
        proxy_pass              http://my-server:80;
    }
 
    #
    # API
    #

    location /api/ {
        rewrite                 ^/api/(.*)                  /api/$1         break;
        proxy_pass              http://other-server;
    }

    #
    # Ping
    #

    location = /ping {
        return 200;
    }


    #
    # Errors
    #

    location = /403 {
        root                    /usr/share/nginx/html/templates/error;
        index                   403.html;
    }
    location = /404 {
        root                    /usr/share/nginx/html/templates/error;
        index                   404.html;
    }
    location = /502 {
        root                    /usr/share/nginx/html/templates/error;
        index                   maintenance.html;
    }

}
根据我的理解,nginx应该在停止之前使用最长前缀进行匹配,但实际情况并非如此。
谢谢

location=/api/v2/macs/
不是前缀位置。如果需要前缀位置,请删除
=
。谢谢你,理查德。这实际上是我的错别字,因为我正在试验不同的解决方案。我已经删除了=并且它仍然不匹配。还有其他建议吗?
location=/api/v2/macs/
不是前缀位置。如果需要前缀位置,请删除
=
。谢谢你,理查德。这实际上是我的错别字,因为我正在试验不同的解决方案。我已经删除了=并且它仍然不匹配。还有其他建议吗?