This article by show according to Lin Feng to provide friendship sponsorship, starting in the mud row World .
After two days of experiments, finally let Nginx support both ASP and PHP. The specific configuration process is documented below.
Note: This experiment os:centos6 64bit.
The Windows environment has not been tested successfully, although there are many Windows Nginx and ASP. NET-integrated data. The following experiments are all performed in a Linux environment. Nginx has been installed successfully and runs as follows:
The Nginx and ASP. NET integration is not through Nginx's reverse proxy function, nor does it use the IIS provided by Windows, but instead uses the Fastcgi_pass to process the ASP, and then gives the processed results to nginx. The plain is to use Nginx as a Web server.
Nginx integration with ASP needs to be divided into the following steps:
1. Mono Installation
2, XSP installation
3. Nginx integration with ASP.
4. Test the integration effect
First, mono installation
To enable Linux to support ASP. NET, we have to install both mono and XSP packages.
The mono package is a cross-platform. NET runtime environment developed by Novell Corporation.
Currently Mono's latest version of the package is mono-3.10.0.tar.bz2, which we can http://download.mono-project.com/sources/mono/through this URL. Download and upload to the CentOS server. As follows:
SCP mono-3.10.0.tar.bz2 [Email protected]:/root
In addition to mono-3.10.0.tar.bz2 this package, we also need to install XSP this software.
XSP is a small. Net Web server that can be used as a Web server, and FASTCGI-MONO-SERVER2/4 can be run as an nginx fastcgi mode.
Currently the latest version of the XSP package is xsp-2.10.2.tar.bz2, which we can http://download.mono-project.com/sources/xsp/through this URL. Download and upload to the CentOS server. As follows:
SCP xsp-2.10.2.tar.bz2 [Email protected]:/root
We first to extract and install Mono,mono software package is relatively large, there is about 70M decompression speed is relatively slow. As follows:
TAR-XVF mono-3.10.0.tar.bz2
After the decompression, enter the extract directory of the Mono software package as follows:
Before installing mono we need to install the relevant packages as follows:
Yum install gcc gcc-c++ glibc glibc-devel glib
Now start configuring Mono, as follows:
./configure
Through, we can also see that currently mono is ready to support. net2.0 to. net4.5.
After the configuration is complete, make compile mono now, as follows:
The make compilation process for mono is slow and requires patience. In this process, we can see that there are many files that have the lo end. These files are the target files compiled with Libtool.
Once the make has been compiled, we will begin the formal installation of Mono, as follows:
Make install
During the installation process, if you look closely, you will see that mono is installed by default in the /usr/local/lib/mono directory. And according to the Linux custom default./configure software is generally under /user/local . Because it is a library, the file is under /user/local/lib .
Of course, we can also view the. /configure–help command at compile time. As follows:
We can see the default installation location for Linux, which is exactly the same as what we mentioned above.
The following picture is mono installed:
Once the installation is complete, we will check the installation location of the next mono based on the information provided at the time of installation. As follows:
As you can see, mono is indeed installed in the/usr/local/lib directory.
Now let's use the MONO–V command to see if Mono is installed successfully. As follows:
Mono–v
The information displayed indicates that mono has been successfully installed.
Note: The Mono command is located under the /usr/local/bin/mono path, as follows:
At the same time, there are already/usr/local/bin in the environment variables of the system, this path. As follows:
Echo $PATH
Second, XSP installation
After mono is installed, we also need to install XSP, the small. NET Web server. Unzip and install the XSP as follows:
TAR-XVF xsp-2.10.2.tar.bz2
Configure the XSP as follows:
./configure
However, you will find that the system prompt error is as follows:
Why do you suggest an error?
because the C # program executes must require a dynamic link library, it is added to the environment variable. And some of the link library mono compiler needs to use, the internal use of the Pkgconfig tool, it is necessary to configure the Pkg_config_path environment variables. The Pkgconfig tool is located under the/usr/local/lib/pkgconfig path. as follows:
All we need to do now is to configure the path of the Pkgconfig tool using the Export command, as follows:
Export pkg_config_path=/usr/local/lib/pkgconfig/
After the path of the Pkgconfig tool is set, we configure the XSP again as follows:
Through can see, now XSP no error.
After the XSP configuration is complete, we will now compile the software by make, as follows:
Make
After compiling the XSP, we will now formally install XSP, as follows:
Make install
XSP the installation is complete, we can view FASTCGI-MONO-SERVER2/4 this program. As follows:
Through, we can see fastcgi-mono-server2/4 This command is located under /usr/local/bin .
It is important to note that this command was done when we started XSP the. Net Web server.
Iii. nginx integration with ASP.
The above is the installation of mono and XSP, and the following is the beginning of integration with Nginx. ASP. NET and Nginx integration, we are through the Nginx virtual host to achieve.
To modify Nginx configuration file nginx.conf, add the following command to the HTTP tag:
server {
Listen 80;
server_name b.ilanni.com;
CharSet Utf-8;
Location/{
root/ilanni/b.ilanni.com;
Index index.aspx index.html index.htm;
Fastcgi_pass 127.0.0.1:9001;
Include Fastcgi_params;
}
}
Note that we have introduced the principle of Nginx and ASP. Nginx through the Fastcgi_pass to process the ASP. NET request, then the processing results to nginx. And Fastcgi_pass is the proxy XSP Web server.
At the same time we also note that the Fastcgi_pass Agent xSP Port is 9001, the port can be arbitrarily defined, as long as the system is not in use with the port conflict.
After this file has been modified, we also need to modify the Fastcgi_params file.
We just need to add two lines of code to the last side of the file. As follows:
Fastcgi_param Path_info "";
Fastcgi_param script_filename $document _root$fastcgi_script_name;
After modifying the files above two files, we now start the XSP Web server. Use the WINS command:
FASTCGI-MONO-SERVER2/APPLICATIONS=/:/ILANNI/B.ILANNI.COM/SOCKET=TCP:127.0.0.1:9001 &
Note that the/ilanni/b.ilanni.com in this command is the root of the Nginx virtual host and 127.0.0.1:9001 is used for XSP 127.0.0.1:9001 this address. & indicates that the command runs in the background.
We can see that the XSP server has started normally, and now we have an ASP. NET probe to test it.
Now let's visit Nginx's virtual host b.ilanni.com, as follows:
Through, we can easily see. Currently, the program is now available for ASP.
Iv. Test Integration effects
Through the above, we are easy to see. Nginx is now fully integrated with ASP. Let's look at the integration of PHP.
In fact, now should not be said to be nginx and PHP integration, because Nginx support PHP is also through the Fastcgi_pass to proxy php-fpm, and then send the results of the request to Nginx.
Now let's create a new Nginx virtual host, as follows:
Access to the virtual host a.ilanni.com. As follows:
So far, we can see that Nginx has fully supported ASP.
Slime: Nginx supports both ASP and PHP