Home Operation and Maintenance Nginx Nginx monitors real-time status configuration and keeps abreast of website operation status

Nginx monitors real-time status configuration and keeps abreast of website operation status

Jul 04, 2023 pm 12:33 PM
nginx monitoring real time status Website operation status

Nginx monitors the real-time status configuration and understands the running status of the website in time

When the website is running, it is very important to understand the real-time status of the server. Nginx is a very popular web server software that provides many monitoring functions to help us understand the operation of the website. This article will introduce how to configure Nginx real-time monitoring and provide some code examples for reference.

1. Install Nginx
First, we need to install the Nginx server. You can compile and install it, or you can use a package manager to install it. Taking the Ubuntu system as an example, you can use the following command to install:

sudo apt-get update
sudo apt-get install nginx
Copy after login

After the installation is completed, you can use the following command to verify whether the installation is successful:

nginx -v
Copy after login

If the version number can be displayed, the installation is successful. .

2. Configure Nginx monitoring module
Nginx provides a very convenient module called ngx_http_stub_status_module, which can be used to monitor the status of Nginx in real time. The following are the steps to configure this module:

  1. Confirm the location of the Nginx configuration file. Normally, the Nginx configuration file is located at /etc/nginx/nginx.conf or /etc/nginx/conf.d/default.conf. You can use the following command to confirm the location of the configuration file:

    nginx -t
    Copy after login
  2. Edit the configuration file. Use a text editor to open the Nginx configuration file:

    sudo vi /etc/nginx/conf.d/default.conf
    Copy after login
  3. Add the following content in the configuration file:

    location /nginx_status {
     stub_status on;
     access_log off;
     allow 127.0.0.1;
     deny all;
    }
    Copy after login

    The above configuration will be in the path /nginx_statusEnable status monitoring under # and limit access to local access only.

  4. Save and exit the configuration file. Restart the Nginx service to make the configuration take effect:

    sudo service nginx restart
    Copy after login

3. Access the Nginx status monitoring page
After the configuration is completed, you can access the Nginx status monitoring page through the browser. Enter http://your_domain/nginx_status in the browser address bar, where your_domain is your server domain name or IP address. If the configuration is correct, you will see a page similar to the following:

Active connections: 1
server accepts handled requests
 16630948 16630948 31070446
Reading: 0 Writing: 1 Waiting: 0
Copy after login

Among them, Active connections represents the current number of active connections; accepts, handled and requests indicate the total number of requests since Nginx started; Reading, Writing and Waiting indicate that Nginx is reading requests, writing Incoming responses and number of waiting connections.

4. Use monitoring API to obtain status data
If you want to obtain Nginx status data programmatically, you can use Nginx's monitoring API. The following is a sample code written in Python to obtain Nginx status information:

import requests

def get_nginx_status():
    url = 'http://your_domain/nginx_status'  # 替换成你的nginx状态监控页面
    response = requests.get(url)
    if response.status_code == 200:
        status = response.text
        return status
    else:
        return None

status = get_nginx_status()
if status:
    print(status)
else:
    print('Failed to get Nginx status')
Copy after login

Note that the url variable is replaced with the URL of your Nginx status monitoring page.

You can get Nginx status information by calling the get_nginx_status function and print it out. The status information returned by this function is a string, which is the same as what you see when accessing the status monitoring page through a browser.

Summary:
Nginx provides powerful monitoring functions that can help us understand the operation of the website in real time. By configuring the ngx_http_stub_status_module module, we can directly access the Nginx status monitoring page in the browser; at the same time, using the Nginx monitoring API, we can also programmatically obtain the Nginx status information for subsequent use. processing and analysis. The above is how Nginx monitors real-time status configuration. I hope it will be helpful to everyone.

The above is the detailed content of Nginx monitors real-time status configuration and keeps abreast of website operation status. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Nginx Performance Tuning: Optimizing for Speed and Low Latency Nginx Performance Tuning: Optimizing for Speed and Low Latency Apr 05, 2025 am 12:08 AM

Nginx performance tuning can be achieved by adjusting the number of worker processes, connection pool size, enabling Gzip compression and HTTP/2 protocols, and using cache and load balancing. 1. Adjust the number of worker processes and connection pool size: worker_processesauto; events{worker_connections1024;}. 2. Enable Gzip compression and HTTP/2 protocol: http{gzipon;server{listen443sslhttp2;}}. 3. Use cache optimization: http{proxy_cache_path/path/to/cachelevels=1:2k

How do I configure Nginx for server-side includes (SSI)? How do I configure Nginx for server-side includes (SSI)? Mar 17, 2025 pm 05:06 PM

The article discusses configuring Nginx for server-side includes (SSI), performance implications, using SSI for dynamic content, and troubleshooting common SSI issues in Nginx.Word count: 159

How do I implement HTTP authentication (basic auth, digest auth) in Nginx? How do I implement HTTP authentication (basic auth, digest auth) in Nginx? Mar 17, 2025 pm 05:03 PM

The article discusses implementing HTTP authentication in Nginx using basic and digest methods, detailing setup steps and security implications. It also covers using authentication realms for user management and suggests combining authentication meth

How do I configure Nginx for URL rewriting and redirection? How do I configure Nginx for URL rewriting and redirection? Mar 17, 2025 pm 05:02 PM

The article discusses configuring Nginx for URL rewriting and redirection, detailing steps and best practices. It addresses common mistakes and testing methods to ensure effective URL management.

How do I monitor Nginx performance and resource usage? How do I monitor Nginx performance and resource usage? Mar 17, 2025 pm 05:08 PM

The article discusses monitoring and optimizing Nginx performance, focusing on using tools like Nginx's status page, system-level monitoring, and third-party solutions like Prometheus and Grafana. It emphasizes best practices for performance optimiza

What are the best tools for monitoring Nginx? What are the best tools for monitoring Nginx? Mar 17, 2025 pm 05:09 PM

The article discusses top Nginx monitoring tools like Datadog, New Relic, and NGINX Amplify, focusing on their features for real-time monitoring, alerting, and detailed metrics to enhance server performance.

How do I configure Gzip compression in Nginx? How do I configure Gzip compression in Nginx? Mar 17, 2025 pm 04:57 PM

The article details how to configure Gzip compression in Nginx, its performance benefits, and verification methods. Main issue: optimizing web server performance through compression.[159 characters]

How do I configure Nginx for WebSocket proxying? How do I configure Nginx for WebSocket proxying? Mar 17, 2025 pm 05:01 PM

Article discusses configuring Nginx for WebSocket proxying, detailing necessary settings and troubleshooting steps for successful WebSocket connections.(159 characters)

See all articles