Nginx中的位置被忽略

问题描述 投票:0回答:1

我在nginx配置中有一个简单的位置,但从未发现

server {
    listen 80 default_server;
    server_name _;

    location /healthcheck {
        access_log off;
        add_header Content-Type "text/plain";
        return 200 "OK\n";
    }

    return 301 http://www.google.fr;
}

[每次我转到http://xxx/healthcheck时都不会检测到该位置,而是将我重定向到Google。

我在档案中做错了什么?谢谢

nginx nginx-location nginx-config
1个回答
0
投票

=前缀意味着指定的位置应与请求的URL完全匹配。

这里是工作设置

server {
    listen 80 default_server;
    server_name _;
    location = /healthcheck {
        access_log off;
        add_header Content-Type "text/plain";
        return 200 "OK\n";
    }

    return 301 http://www.google.fr;
}

OR

server {
    listen 80 default_server;
    server_name _;
    location /healthcheck {
        access_log off;
        add_header Content-Type "text/plain";
        return 200 "OK\n";
    }
}

Note:不要忘记在所有更改sudo nginx -s reload]之后重新加载nginx

© www.soinside.com 2019 - 2024. All rights reserved.