Master Nginx Static‑Dynamic Separation: Boost Web Performance with Simple Config

This article explains the concept of Nginx static‑dynamic separation, shows how to configure Nginx to serve static files directly while proxying dynamic requests to backend servers, and includes a sample configuration with code snippets, plus a call‑to‑action for additional architecture resources.

Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Master Nginx Static‑Dynamic Separation: Boost Web Performance with Simple Config

Nginx Static‑Dynamic Separation

Nginx is a must‑have skill for large‑scale architectures. Static‑dynamic separation is a web‑architecture optimization strategy that handles dynamic requests and static resources separately.

Static resources such as HTML, CSS, JavaScript, images, etc., are served directly from the file system or cache, while dynamic content generated by PHP, Python, or other back‑end services is forwarded to application servers.

The principle relies on configuring different location blocks and upstream definitions in Nginx.

Configuration Example

server {
    listen 80;
    server_name example.com;
    # Static resource handling
    location ~* \.(jpg|jpeg|png|gif|css|js)$ {
        root /data/static/;
        expires 30d; # browser cache
    }
    # Dynamic request forwarding
    location / {
        proxy_pass http://backend_server;
    }
}

When a URL matches a static‑resource pattern (e.g., .html, .css, .js, .jpg, .png), Nginx returns the file directly. When a URL matches a dynamic pattern (e.g., .php, .jsp, /api/), the request is proxied to the back‑end server.

Static matching is done via regular expressions or file extensions, while dynamic matching uses URL characteristics.

Diagram of static‑dynamic separation
Diagram of static‑dynamic separation
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.

Web Performancestatic-dynamic separation
Mike Chen's Internet Architecture
Written by

Mike Chen's Internet Architecture

Over ten years of BAT architecture experience, shared generously!

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.