nginx - 如何使用stub_status创建状态?

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

我试图创建一个状态来使用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.comtipsnginxnginx-new-relic-plugin#

nginx newrelic
1个回答
1
投票

删除。

  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

新Relic配置。

url=http://localhost/nginx_status
© www.soinside.com 2019 - 2024. All rights reserved.