0

Zabbix shows 301 error when trying to get nginx_status.

This is how my zabbix.conf looks like:

server {

listen [::]:80;
server_name 127.0.0.1;
location /nginx_status {
    stub_status on;
    access_log off;
    allow 127.0.0.1;
    deny all;
    access_log off;
    error_log  /var/log/nginx/nginx_status_error.log;
}

location ~ ^/(status|ping)$ {
    include fastcgi_params;
    fastcgi_pass 127.0.0.1:7777;
    fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
    allow 127.0.0.1;
    deny all;
    }

}

When I try to curl I get this error:

$ curl 127.0.0.1:80/status
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>

There is no messages in /var/log/nginx/nginx_status_error.log

I am not sure why this is happaning and where to find root cause. What should I do or check to get rid of this error?

EDIT:

$ curl -i 127.0.0.1:80/status
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Mon, 21 Oct 2019 11:01:17 GMT
Content-Type: text/html
Content-Length: 162
Connection: keep-alive
Location: https://127.0.0.1/status

<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>

SOLUTION:

I commented listen [::]:80; and add port to server_name 127.0.0.1:80;. Now I get:

$ curl -i 127.0.0.1:80/status
HTTP/1.1 200 OK
  • Please give the output of curl -i 127.0.0.1:80/status so we can see where it wants to redirect, maybe it's only trying to redirect from /status to /status/ or something like that? – Ulrich Schwarz Oct 21 at 10:34
  • @UlrichSchwarz I updated my post adding curl -i output. – Brzozova Oct 21 at 11:10
  • Oh, you seem to have a redirect that forces everything to encrypted https connections. (But connecting to https://127.0.0.1/status is very likely to give you a certificate error since no reputable source will issue certificates for 127.0.0.1.) – Ulrich Schwarz Oct 21 at 11:19
  • You're right, thanks! Where can I change this? Should I add server_name http://127.0.0.1/ to force http? – Brzozova Oct 21 at 11:59
  • 1
    Welcome, You can answer your question instead of editing. – GAD3R Oct 22 at 6:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.