Nginx在查询字符串之前自动添加尾部斜杠

时间:2019-02-06 14:34:32

标签: nginx nginx-reverse-proxy

当我连接到: http://localhost/api?foo=bar

Nginx将我重定向到: http://localhost/api/?foo=bar

因此,我的支持者无法正确响应。

我尝试将位置更改为location /api,然后问题解决了,但它也与http://localhost/apiapi?foo=bar之类的东西匹配,我不希望这样。

这是我的配置:

server {
    listen 80;
    server_name localhost;

    location / {
        root /usr/share/nginx/html;
        index index.html;
    }

    location /api/ {
        proxy_pass http://127.0.0.1:3000;
    }
}

1 个答案:

答案 0 :(得分:0)

您要使用URI /api来访问您的服务。

除非添加了额外的location /api/(Nginx会通过重定向自动附加),否则/与该API不匹配。

location /api也匹配任何以相同的三个字符开头的URI。

由于您的服务仅需要响应单个URI,因此您可以使用完全匹配location

例如:

location = /api {
    ...
}

有关详细信息,请参见this document

相关问题