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.
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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Mike Chen's Internet Architecture
Over ten years of BAT architecture experience, shared generously!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
