我正在尝试创建一个用于新文物的/status,但它总是返回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文件(它也使用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并遵循以下指南:https://www.scalescale.com/tips/nginx/nginx-new-relic-plugin/#
发布于 2020-06-08 20:19:34
移除:
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发布于 2021-08-17 22:00:52
对我来说,接受的答案不起作用(尽管从编码的角度来看可能是正确的)
我只需要重新启动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
https://stackoverflow.com/questions/62269902
复制相似问题