Reverse proxy for ASP. NET with nginx+mono+fastcgi instead of IIS

Source: Internet
Author: User

The benefits of Nginx believe me needless to say, it is very popular as a fairly lightweight open source Web server and a reverse proxy server. More and more companies are already interested in it, including many of our company's departments, using it for load balancing and resource management, before writing an article about load Balancing with Nginx (http://www.cnblogs.com/liping13599168/ archive/2011/04/15/2017369.html).

This article describes how to reverse proxy through Nginx, and run the ASP. 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

Unpack the package to see the directory:

Nginx is the execution of the file entry, open the Conf directory, you can see the nginx.conf file, this as the main configuration of Nginx Portal:

server {
Listen 8000;
server_name 127.0.0.1;

#charset Koi8-r;

...

}

Here I change the default of 80 to 8000, as the default port of Nginx Web server, from here we can understand that, 8000 as a Web site published by the website, that is, the proxy service port, now I can let it host the relevant Web site in the intranet.

Now I add a new site on the IIS server:

To deploy an ASP. NET Web site, port set to 88, 88 port can be considered as a non-open port in the intranet, the site is placed in directory D:\WebApplication\WebApplication, and now modify the configuration in nginx.conf:

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;
}

Where the root parameter can set the corresponding Web site directory, index can set the site's default page, Proxy_pass for IIS in the 88-port corresponding site proxy;

Now start Nginx, the command is: Start nginx; the Stop command is: Nginx–s stop

Now enter in the browser: http://127.0.0.1:8000/, display:

ok! Test Success, this is the implementation of the site in IIS reverse proxy, of course, you can also reverse proxy to other Web servers, such as apache,resin,fastcgi, and so on. Here I want to share a scenario in which fastcgi replaces IIS as a Web server.

We may know that the deployment of mono on Linux can be run in a non-IIS way, including APACHE,RESIN,FASTCGI,LIGHTTPD and so on, Now we are using Mono's fastcgi module on Windows to run an ASP. NET Web site in a non-IIS host scenario.

To the Mono official website, download the mono for Windows version installation package:

Http://www.go-mono.com/mono-downloads/download.html

Download the package for Mono-2.10.8-gtksharp-2.12.11-win32-1.exe, install it, and include Mono's related DLLs in our local GAC;

Continue to create an ASP. NET site, this time do not need to deploy the site IIS above, this time using nginx through the fastcgi to reverse proxy. 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;
}

Where the Web is the directory of the site, Fastcgi_index as the default page of FastCGI, Fastcgi_pass set its site, here set a port 9000, in fact, it is a TCP protocol 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, which can be used in two ways: Fastcgi-mono-server2 and Fastcgi-mono-server4, The former corresponds to the CLR2.0 runtime host, which 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, then re-execute Nginx, in the browser again input: http://127.0.0.1:8000/default.aspx, display:

Reverse proxy for ASP. NET with nginx+mono+fastcgi instead of IIS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.