How to Build a Windows Nginx Reverse Proxy and Load‑Balancing Cluster with IIS
This article explains the principles of reverse proxy, introduces Nginx’s core features, and provides a step‑by‑step guide to set up a Windows‑based Nginx reverse‑proxy server that load‑balances two IIS‑hosted ASP.NET sites, including configuration, service registration, caching, and testing.
Reverse Proxy: The "Broker" of Web Servers
A reverse proxy receives Internet requests, forwards them to internal servers, and returns the responses, appearing to clients as a single server.
Benefits of a Reverse Proxy
Security : All external requests must pass through the proxy.
Caching : Static resources can be cached to reduce load on the origin server.
Load Balancing : Distributes requests across multiple backend servers.
Introducing Nginx
Nginx is a lightweight web server, reverse proxy, and mail proxy released under a BSD‑like license. It is known for stability, rich feature set, low resource consumption, and an event‑driven architecture based on the epoll model.
Key characteristics:
Cross‑platform : Runs on most Unix‑like OSes and Windows.
Simple configuration : Configuration syntax is concise and developer‑friendly.
Non‑blocking high concurrency : Supports up to 50 000 concurrent connections in tests; typical production sees 20‑30 000.
Event‑driven (epoll) : Efficient handling of many simultaneous connections.
Master/Worker model : A master process spawns multiple worker processes; workers handle requests independently, improving fault tolerance.
Low memory usage : 10 workers consume about 150 MB under 30 000 connections.
Built‑in health checks : Backend failures do not affect front‑end availability.
GZIP compression and bandwidth saving .
High stability as a reverse proxy.
Practical Build: Nginx + IIS Load‑Balancing on Windows
1. Prepare two ASP.NET sites on IIS
Create an ASP.NET Web application in Visual Studio, duplicate it, and modify the default pages so one shows "The First Web" and the other "The Second Web". Deploy both sites to IIS on different ports (e.g., 8050 and 8060).
2. Install Nginx and run it as a Windows service
Download the Windows version of Nginx (e.g., nginx‑1.4.7) and extract it, e.g., to D:\Servers\nginx-1.4.7. Start, stop, and reload the service with:
start nginx.exe nginx -s stop nginx -s reloadRegister Nginx as a Windows service using the "Windows Service Wrapper" (winsw). Rename the executable (e.g., nginx-service.exe) and place it in the Nginx directory.
Create an XML configuration file named nginx-service.xml with the following content:
<?xml version="1.0" encoding="UTF-8"?>
<service>
<id>nginx</id>
<name>Nginx Service</name>
<description>High Performance Nginx Service</description>
<executable>D:\Servers
ginx-1.4.7
ginx.exe</executable>
<logpath>D:\Servers
ginx-1.4.7\</logpath>
<logmode>roll</logmode>
<depend></depend>
<startargument>-p D:\Servers
ginx-1.4.7</startargument>
<stopargument>-p D:\Servers
ginx-1.4.7 -s stop</stopargument>
</service>Install the service with: nginx-service.exe install After installation, set the service startup type to "Automatic" in the Windows Services manager.
3. Edit nginx.conf
Process and connection settings
Set the number of worker processes to the number of CPU cores.
Define worker_connections to control the maximum connections per worker.
Basic server block
server {
listen 80;
server_name www.example.com example.com;
location / {
proxy_pass http://backend;
}
}Upstream (load‑balancing) list
upstream backend {
server 127.0.0.1:8050 weight=2;
server 127.0.0.1:8060 weight=1;
}The weight parameter controls how many requests each backend receives relative to the others.
4. Cache static resources
To improve response speed, configure caching for images, CSS, and JavaScript:
location ~* \.(jpg|jpeg|png|gif)$ {
root /nginx-1.4.7/staticresources/image;
expires 7d;
}
location ~* \.(css)$ {
root /nginx-1.4.7/staticresources/css;
expires 7d;
}
location ~* \.(js)$ {
root /nginx-1.4.7/staticresources/js;
expires 7d;
}5. Test the load‑balancing effect
Access http://localhost/Default.aspx repeatedly. The first request is served by the site on port 8050, the second by the site on port 8060, and subsequent requests alternate according to the configured weights.
Learning Summary
This tutorial demonstrates how to use Nginx as a reverse proxy on Windows to achieve simple load balancing for IIS‑hosted ASP.NET applications. While production environments typically run Nginx on Linux with more advanced tuning, the presented steps provide a solid foundation for further exploration.
References
Ding Pangpang, "Illustrated Forward, Reverse and Transparent Proxy".
Special Forces AK47, "Differences Between Forward and Reverse Proxy".
Baike, "Nginx".
51CTO, "Nginx Installation, Configuration and Service Building".
Red‑Black Alliance, "Detailed Nginx Configuration File Analysis".
360doc, "Linux Synchronous, Asynchronous, Blocking and Non‑Blocking Summary".
e路相扶, "Synchronous, Asynchronous, Blocking and Non‑Blocking".
feitianxuxue, "Understanding Asynchronous Non‑Blocking for High Concurrency".
Download Links
nginx‑1.4.7: http://pan.baidu.com/s/1dD2C2zB
winsw‑1.8‑bin.exe: http://pan.baidu.com/s/1kTihzk7
SimpleNginxDemo: http://pan.baidu.com/s/1bnq5oYz
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.
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.
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.
