nginx - 如何使用 stub_status 创建 /status
nginx - how to create /status with stub_status
我正在尝试创建一个 /status 以与 newrelic 一起使用,但它总是返回 404。
$ curl 127.0.0.1/status
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.17.1</center>
</body>
</html>
这是我的 nginx conf 文件(它也使用 certbot)。
server {
server_name mysite.com api.mysite.com painel.mysite.com;
location / {
root /var/www/mysite-prod/public;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.(php|phar)(/.*)?$ {
root /var/www/mysite-prod/public;
fastcgi_split_path_info ^(.+\.(?:php|phar))(/.*)$;
fastcgi_intercept_errors on;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass php-fpm;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mysite.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mysite.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
location = /status { <============== HERE
stub_status on;
default_type text/plain;
access_log off;
allow 127.0.0.1;
deny all;
}
if ($host = panel.mysite.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = api.mysite.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = mysite.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name mysite.com api.mysite.com painel.mysite.com;
listen 80;
return 404; # managed by Certbot
}
我是不是做错了什么?
我正在使用 AWS Linux 并遵循了本指南:https://www.scalescale.com/tips/nginx/nginx-new-relic-plugin/#
删除:
location = /status { <============== HERE
stub_status on;
default_type text/plain;
access_log off;
allow 127.0.0.1;
deny all;
}
然后创建一个新的配置文件 status.conf
,内容如下:
server {
listen localhost;
server_name status.localhost;
keepalive_timeout 0;
access_log off;
allow 127.0.0.1;
deny all;
location /nginx_status {
stub_status on;
}
}
重新加载 Nginx 配置:
sudo nginx -s reload
测试 URL:
$ curl http://127.0.0.1/nginx_status
Active connections: 6
server accepts handled requests
1285282 1285282 17041299
Reading: 0 Writing: 6 Waiting: 0
新遗迹配置:
url=http://localhost/nginx_status
对我来说,接受的答案不起作用(尽管从编码的角度来看可能是正确的)
我只需要重新启动 nginx
sudo service nginx restart
我做的任何sudo nginx -s reload
都会回馈404。
我的配置文件
server {
listen localhost;
location /nginx_status {
stub_status on;
allow 127.0.0.1;
deny all;
}
}
nginx 版本:nginx/1.20.1
我正在尝试创建一个 /status 以与 newrelic 一起使用,但它总是返回 404。
$ curl 127.0.0.1/status
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.17.1</center>
</body>
</html>
这是我的 nginx conf 文件(它也使用 certbot)。
server {
server_name mysite.com api.mysite.com painel.mysite.com;
location / {
root /var/www/mysite-prod/public;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.(php|phar)(/.*)?$ {
root /var/www/mysite-prod/public;
fastcgi_split_path_info ^(.+\.(?:php|phar))(/.*)$;
fastcgi_intercept_errors on;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass php-fpm;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mysite.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mysite.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
location = /status { <============== HERE
stub_status on;
default_type text/plain;
access_log off;
allow 127.0.0.1;
deny all;
}
if ($host = panel.mysite.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = api.mysite.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = mysite.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name mysite.com api.mysite.com painel.mysite.com;
listen 80;
return 404; # managed by Certbot
}
我是不是做错了什么?
我正在使用 AWS Linux 并遵循了本指南:https://www.scalescale.com/tips/nginx/nginx-new-relic-plugin/#
删除:
location = /status { <============== HERE
stub_status on;
default_type text/plain;
access_log off;
allow 127.0.0.1;
deny all;
}
然后创建一个新的配置文件 status.conf
,内容如下:
server {
listen localhost;
server_name status.localhost;
keepalive_timeout 0;
access_log off;
allow 127.0.0.1;
deny all;
location /nginx_status {
stub_status on;
}
}
重新加载 Nginx 配置:
sudo nginx -s reload
测试 URL:
$ curl http://127.0.0.1/nginx_status
Active connections: 6
server accepts handled requests
1285282 1285282 17041299
Reading: 0 Writing: 6 Waiting: 0
新遗迹配置:
url=http://localhost/nginx_status
对我来说,接受的答案不起作用(尽管从编码的角度来看可能是正确的)
我只需要重新启动 nginx
sudo service nginx restart
我做的任何sudo nginx -s reload
都会回馈404。
我的配置文件
server {
listen localhost;
location /nginx_status {
stub_status on;
allow 127.0.0.1;
deny all;
}
}
nginx 版本:nginx/1.20.1