简体   繁体   English

在 nginx 中忽略位置

[英]Location ignored in nginx

I've a simple location in my nginx config but never catched我的 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;
}

Everytime I go to http://xxx/healthcheck the location is not detected and I'm redirected to Google.每次我去http://xxx/healthcheck都没有检测到位置,我被重定向到谷歌。

What did I do wrong in my file?我在我的文件中做错了什么? Thanks谢谢

Please switch 301 to 302 redirect code and use anon mode in browser, or better use curl to check healthcheck url.请将301转302重定向代码并在浏览器中使用anon模式,或者最好使用curl来检查healthcheck url。 For example:例如:

curl -IL http://xxx/healthcheck

301 is always a problem when you are testing something.当您测试某些东西时,301 始终是一个问题。

Change won't be imidiate.改变不会被模仿。 Please be patient.请耐心等待。 Let us know让我们知道

The = prefix means that the location specified should exactly match the requested URL. =前缀意味着指定的位置应该与请求的 URL 完全匹配。

Here is the working setting这是工作设置

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 : Don't forget to reload nginx after all the changes sudo nginx -s reload注意:不要忘记在所有更改后重新加载 nginx sudo nginx -s reload

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM