What Nginx Can Do Without Third‑Party Modules: Reverse Proxy, Load Balancing, HTTP Server, and More
This article explains the core functions Nginx can perform without any third‑party modules—including reverse proxy, load balancing with various strategies, static HTTP serving, dynamic/static separation, and forward proxy—while providing detailed configuration examples and command‑line operations.
Nginx Capabilities Without Third‑Party Modules
Reverse proxy
Load balancing (RR, weight, ip_hash, fair, url_hash)
HTTP server (static files and dynamic/static separation)
Forward proxy
The following sections describe each capability and show how to configure it using only the built‑in features of Nginx.
Reverse Proxy
A reverse proxy receives client requests from the Internet and forwards them to internal servers, returning the responses to the clients. A simple reverse‑proxy configuration looks like this:
server {
listen 80;
server_name localhost;
client_max_body_size 1024M;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host:$server_port;
}
}After saving the configuration and starting Nginx, accessing http://localhost will actually serve content from http://localhost:8080 .
Load Balancing
Load balancing distributes requests across multiple backend servers. Nginx provides several built‑in strategies and supports additional third‑party methods.
Round‑Robin (default)
upstream test {
server localhost:8080;
server localhost:8081;
}
server {
listen 81;
server_name localhost;
client_max_body_size 1024M;
location / {
proxy_pass http://test;
proxy_set_header Host $host:$server_port;
}
}Weight
upstream test {
server localhost:8080 weight=9;
server localhost:8081 weight=1;
}With the above settings, roughly 9 out of 10 requests go to localhost:8080 and 1 out of 10 to localhost:8081 .
ip_hash
upstream test {
ip_hash;
server localhost:8080;
server localhost:8081;
}Requests from the same client IP are consistently routed to the same backend, which helps when sessions are stored locally.
fair (third‑party)
upstream backend {
fair;
server localhost:8080;
server localhost:8081;
}url_hash (third‑party)
upstream backend {
hash $request_uri;
hash_method crc32;
server localhost:8080;
server localhost:8081;
}Each of the five strategies suits different scenarios; note that fair and url_hash require third‑party modules, which are not covered here.
HTTP Server
Nginx can serve static files directly. A minimal static‑file server configuration is:
server {
listen 80;
server_name localhost;
client_max_body_size 1024M;
location / {
root e:\wwwroot;
index index.html;
}
}Visiting http://localhost will return e:\wwwroot\index.html .
Dynamic/Static Separation
upstream test {
server localhost:8080;
server localhost:8081;
}
server {
listen 80;
server_name localhost;
location / {
root e:\wwwroot;
index index.html;
}
# Static resources handled by Nginx
location ~ \.(gif|jpg|jpeg|png|bmp|swf|css|js)$ {
root e:\wwwroot;
}
# Dynamic requests forwarded to Tomcat
location ~ \.(jsp|do)$ {
proxy_pass http://test;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root e:\wwwroot;
}
}This setup serves static assets directly while proxying dynamic requests (e.g., JSP) to a backend application server.
Forward Proxy
A forward proxy sits between a client and the origin server. A basic forward‑proxy configuration is:
resolver 114.114.114.114 8.8.8.8;
server {
resolver_timeout 5s;
listen 81;
access_log e:\wwwroot\proxy.access.log;
error_log e:\wwwroot\proxy.error.log;
location / {
proxy_pass http://$host$request_uri;
}
}Clients can configure their browsers or proxy tools to use IP:81 as the proxy server.
Managing Nginx
Common commands for starting, stopping, and reloading Nginx:
/etc/init.d/nginx start/restart # start or restart Nginx service
/etc/init.d/nginx stop # stop Nginx service
/etc/nginx/nginx.conf # location of the main configuration file
nginx -s reload # reload configuration without stopping the serviceNginx supports hot reload, so changes to the configuration take effect immediately after running the reload command.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
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.