The benefits of Nginx believe that I don’t need to say more, as a fairly lightweight open source Web
server and reverse proxy server are very popular. More and more companies have become interested in it, including many departments of our company, using it for load balancing and resource management. I wrote an article about using Nginx for load balancing article (http://www.cnblogs.com/liping13599168/archive/2011/04/15/2017369.html).
“
This article introduces how to reverse proxy through Nginx and run the asp.net website. I use the Win7 system for the test environment.
First, you need to download the Nginx installation package:
http://nginx.org/en/download.html, here I download the latest version: nginx/Windows-1.1.16
Unzip the package to see the directory:
Nginx is the entry of the execution file, open the conf directory, you can see the nginx.conf file, this is the main configuration entry of Nginx:
server {
listen 8000;
“ server_name`
127.0.0.1;
#charset koi8-r;
…
}
Here I change the default 80 to 8000 as the default port of the nginx web server. From here we can understand that 8000 is the web port announced by the website, that is, the port of the proxy service. Now, I can let it host the internal Related Web sites on the Internet.
Now I add a new site on the IIS server:
Deploy an asp.net website on it, the port is set to 88, port 88 can be regarded as a non-open port in the intranet, and the website is placed in the directory
In D:\WebApplication\WebApplication, modify the configuration in nginx.conf to:
location / {
root D:\WebApplication\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;
}
Among them, the root parameter can set the directory of the corresponding website, the index can set the default page of the site, and proxy_pass is used to proxy the site corresponding to port 88 in IIS;
Now start nginx, the command is: start nginx; and the stop command is: nginx ?s stop
Now enter in the browser: http://127.0.0.1:8000/, display:
OK! The test is successful, so the reverse proxy to the site in IIS is realized. Of course, you can also perform reverse proxy to other web servers, such as Apache, Resin, Fastcgi and so on. Here I want to share a solution for Fastcgi instead of IIS as a web server.
“
We may know that the deployment and operation of Mono on Linux can be run through non-IIS methods, including Apache, Resin, Fastcgi, Lighttpd, etc. Now we use Mono’s Fastcgi module on Windows to run under non-IIS host conditions asp.net website.
Go to the Mono official website to download the Mono for windows version installation package:
http://www.go-mono.com/mono-downloads/download.html
The download package is mono-2.10.8-gtksharp-2.12.11-win32-1.exe, install it, and include the related DLL of Mono on our local GAC;
Continue to create an asp.net site. This time, it is not necessary to deploy the site on IIS. This time, use nginx to perform reverse proxy through fastcgi. Modify the nginx.conf configuration file to:
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;
}
Among them, Web is the directory where the site is stored, fastcgi_index is the default page of fastcgi, fastcgi_pass
Set its site, here set a port 9000, in fact it is a port of the tcp protocol.
In addition, these two lines need to be added to 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 methods: fastcgi-mono-server2 and fastcgi-mono-server4, the former corresponds to the CLR2.0 runtime host, and the latter corresponds to the CLR4.0 runtime host:
fastcgi-mono-server2 /applicatiOns=/:.
/socket=tcp:127.0.0.1:9000 /port=8000
/root=”F:\nginx-1.1.16\Web”
Execute it, then re-execute nginx, enter again in the browser: http://127.0.0.1:8000/default.aspx, display:
it shows good! It shows that the configured asp.net site has been running well in the case of non-IIS:)