I don't have to say much about the benefits of Nginx. It is very popular as a lightweight open-source Web server and reverse proxy server. More and more companies are interested in it, including many departments in our company, using it for load balancing and resource management, I have previously written an article about using Nginx for Load Balancing (http://www.cnblogs.com/liping13599168/archive/2011/04/15/2017369.html ).
This article describes how to use Nginx for reverse proxy and run the asp.net website. I use Win7 in the testing environment.
First, download the Nginx installation package:
Http://nginx.org/en/download.html, here I download the latest release: nginx/windows-1.1.16
Decompress the package to view the directory:
Nginx is the entry to the execution file. Open the conf directory and you can see the nginx. conf file. This is the main configuration entry for Nginx:
Server {
Listen 8000;
Server_name 127.0.0.1;
# Charset koi8-r;
...
}
Here, I change the default port 80 to 8000 as the default port of the nginx Web server. Here we can understand that 8000 is the Web port published by the website, that is, the port of the proxy service, now, I can let it host the relevant Web sites in the intranet.
Now I want to add a new site on the IIS server:
Deploy an asp.net website on the top. The port is set to port 88,88, which can be regarded as a non-open port in the Intranet. The website is placed in the Directory D: \ WebApplication. Now modify nginx. the configuration in conf is as follows:
Location /{
Root D: \ WebApplication;
Index index.html index.htm default. aspx Default. aspx;
Proxy_pass http: // 127.0.0.1: 88;
Proxy_set_header X-Real-IP $ remote_addr;
}
Here, the root parameter can be set to the directory of the corresponding website, index can be set to the default page of the site, proxy_pass proxy for the site corresponding to port 88 in IIS;
Start nginx now. The command is start nginx, and the stop command is nginx-s stop.
Enter "http: // 127.0.0.1: 8000/" in the browser:
OK! If the test is successful, the reverse proxy is implemented for the site in IIS. Of course, you can reverse proxy other Web servers, such as Apache, Resin, Fastcgi, and so on. Here I want to share a solution for replacing IIS with Fastcgi as a Web server.
We may know how to deploy and run Mono on Linux, which can be run in non-IIS mode, including Apache, Resin, Fastcgi, Lighttpd, etc, now we use the Fastcgi module of Mono on Windows to run the asp.net website without the IIS host.
Go to the Mono official website to download the Mono for windows installation package:
Http://www.go-mono.com/mono-downloads/download.html
Download the package mono-2.10.8-gtksharp-2.12.11-win32-1.exe, install it, and include the related Mono DLL on our local GAC;
Continue to create an asp.net site. This time, you do not need to deploy the site on IIS. This time, nginx is used for reverse proxy through fastcgi. Modify the nginx. conf configuration file:
Location /{
Root Web;
Index index.html index.htm default. aspx Default. aspx;
Fastcgi_index Default. aspx;
Fastcgi_pass 127.0.0.1: 9000;
Include fastcgi_params;
}
The Web is the directory where the site is stored, and fastcgi_index is the default page of fastcgi. fastcgi_pass sets its site. Here, a port 9000 is set, which is actually a tcp port.
In addition, you need to add these two lines in the fastcgi_params configuration file:
Fastcgi_param PATH_INFO "";
Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
Now run Mono-2.10.8 Command Prompt:
Enter the fastcgi-mono-server command in mono, you can use two ways: fastcgi-mono-server2 and fastcgi-mono-server4, the former corresponds to CLR2.0 runtime host, the latter corresponds to CLR4.0 runtime Host:
Fastcgi-mono-server2/applications =/:./socket = tcp: 127.0.0.1: 9000/port = 8000/root = "F: \ nginx-1.1.16 \ Web"
Run the following command and then run nginx again. Enter http: // 127.0.0.1: 8000/default. aspx in the browser again:
Display normal! It indicates that the configured asp.net site has run well without IIS :)