Iis + nginx load balancing and iisnginx Load Balancing
Brief description: nginx introduction Baidu.
Objective: To distribute user requests to servers to relieve pressure. Nginx evenly forwards requests from listening ports to servers deployed on the website.
1. Install nginx on windows 1. Download nginx http://nginx.org/en/docs/windows.html for windows
The latest version is 1.13.2.
2. Download and unzip the package
3. Because port 80 of my computer has been used, modify the configuration file to listen to port 8080.
4. Double-click the main program to run the program. You can see that nginx is already running in the process.
5. If http: // localhost: 8080/appears, nginx installation is successful.
2. Build two identical sites. 1. The website has only one home page.
Public class HomeController: Controller {// GET: Home public ActionResult Index () {List <string> info = new List <string> (); info. add ("Server name:" + Server. machineName); info. add ("Nginx IP Address:" + (Request. userHostAddress = ": 1 "? "127.0.0.1": Request. userHostAddress); info. add ("Real customer IP Address:" + Request. headers ["X-Real-IP"]); info. add ("HTTP port:" + Request. url. port); ViewBag.info = info; return View ();}}
2. Because my nginx is installed in a virtual machine, a site is deployed in iis on the virtual machine. The port is 9000.
3. A site is deployed on the local machine. The port is 9001.
3. Modify the nginx configuration file 1. Add upstream (server cluster) under the http node. The server sets the information of the Cluster server. I have set up two sites and configured two sites here.
2. Locate the location node change under the http Node
Location /{
Root html;
Index Home/Index index.html index.htm; # modify the Home page to Home/Index
# Jq_one corresponds to the cluster name set by upstream.
Proxy_pass http: // Jq_one;
# Set the Host header and client real address so that the server can obtain the real IP address of the client
Proxy_set_header Host $ host;
Proxy_set_header X-Real-IP $ remote_addr;
Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
}
The modified configuration file:
3. Restart Nginx
Enter the nginx-s reload command and press Enter.
Restart completed
Iv. Verification
Try to access the listening port 8080 and refresh it several times.
Here, the IP address of the virtual machine is http: // 192.9.200.44. The Nginx listening port for accessing the virtual machine from the host.
5. Make Nginx into a service, boot 1. With a small tool winsw https://github.com/kohsuke/winsw/releases
Download the simple configuration and. net environment files. According to your own environment, the. net4
Put it in any directory, put it together with nginx, and change the two files to the same name.
2. modify the configuration file
3. Install the service
Run myapp.exe install to install the service.
Now nginx is in the service and you can start the service.
Complete.
References: http://www.cnblogs.com/jbps/p/5721477.html