79

详解:配置启用NGINX状态页面

 6 years ago
source link: https://www.linuxprobe.com/nginx-state-page.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
导读 Nginx是一款免费的开源,高性能,可靠,可扩展且可完全扩展的Web服务器,负载均衡器和反向代理软件。 它有一个简单和易于理解的配置语言。 它还支持多种静态模块(自第一个版本开始就存在于Nginx中)和动态模块 (在1.9.11版本中引入 )。

Nginx中的一个重要模块是ngx_http_stub_status_module模块,它通过“ 状态页面 ”提供对基本Nginx状态信息的访问。 它显示活动客户端连接总数,接受和处理的总数,请求总数以及读取,写入和等待连接数等信息。

在大多数Linux发行版上, Nginx版本随ngx_http_stub_status_module启用。 您可以使用以下命令检查模块是否已启用。

# nginx -V 2>&1 | grep -o with-http_stub_status_module

检查Nginx状态模块

如果在终端中看到--with-http_stub_status_module作为输出,则表示状态模块已启用。 如果上述命令没有返回任何输出,则需要使用-with-http_stub_status_module作为配置参数从源代码编译NGINX ,如图所示。

# wget http://nginx.org/download/nginx-1.13.12.tar.gz
# tar xfz nginx-1.13.12.tar.gz
# cd nginx-1.13.12/
# ./configure --with-http_stub_status_module
# make
# make install

在验证模块之后,您还需要在NGINX配置文件/etc/nginx/nginx.conf中启用stub_status模块,以便为该模块设置一个本地可访问的URL(例如http://www.example.com/nginx_status )状态页面。

location /nginx_status {
stub_status;
allow 127.0.0.1;	#only allow requests from localhost
deny all;		#deny all other hosts	
}

启用Nginx状态页面

确保将127.0.0.1替换为服务器的IP地址,并确保只有您可访问此页面。

更改配置后,请确保检查nginx配置是否有任何错误,并使用以下命令重新启动nginx服务以实现最近的更改。

# nginx -t
# nginx -s reload 

检查Nginx配置

重新加载nginx服务器后,现在您可以使用curl程序访问下面的URL中的Nginx状态页面来查看您的指标。

# curl http://127.0.0.1/nginx_status
OR
# curl http://www.example.com/nginx_status

检查Nginx状态页面

重要说明 : ngx_http_stub_status_module模块已被Nginx 1.13.0版本中的ngx_http_api_module模块取代。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK