Master Nginx: Custom Error Pages, Status Monitoring, and Performance Tuning

This guide explains how to customize Nginx 404 error pages, enable and view the built‑in status module, increase concurrency limits, adjust client header buffers, and configure browser caching for static assets, providing step‑by‑step commands and configuration snippets.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Nginx: Custom Error Pages, Status Monitoring, and Performance Tuning

Nginx is a high‑performance web and reverse‑proxy server that consumes little memory and handles high concurrency, making it a popular alternative to Apache for large Chinese internet companies such as Taobao, JD, Baidu, Sina, NetEase, and Tencent.

1. Customizing the 404 error page

Before optimization, accessing a non‑existent URL returns the default "404 Not Found" page. To define a custom error page, edit /usr/local/nginx/conf/nginx.conf and add error_page 404 /404.html;, then create the 404.html file and reload Nginx.

2. Viewing server status information

Compile Nginx with --with-http_stub_status_module to enable the status page. After enabling, add a location block:

location /status {
    stub_status on;
    #allow IP;
    #deny IP;
}

Reload Nginx and query curl http://<em>IP</em>/status to see active connections, accepts, handled, requests, reading, writing, and waiting counts.

3. Increasing concurrency

Run an ab load test and observe "Too many open files" errors. Increase worker_processes (typically to the number of CPU cores) and worker_connections 65535; in the events block, then reload.

Adjust Linux limits with ulimit -Hn 100000 and ulimit -Sn 100000, and persist them in /etc/security/limits.conf by setting * soft nofile 100000 and * hard nofile 100000.

4. Expanding client header buffers

When a long URL triggers a "414 Request‑URI Too Large" error, increase the buffers in the http block:

client_header_buffer_size 1k;
large_client_header_buffers 4 4k;

Reload Nginx and re‑run the script to verify the request succeeds.

5. Browser‑side static file caching

In Firefox, view the cache via about:cache. To set caching for static assets, add a location block matching common file extensions and specify expires 30d;:

location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
    expires 30d;
}

Place a test image in /usr/local/nginx/html, reload, and verify the cache headers in the browser.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

cachingperformance tuningError PageServer Status
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.