How does nginx support both asp.net and php configurations?

Source: Internet
Author: User

After two days of experiments, nginx was finally supported by asp.net and php at the same time. The specific configuration process is recorded as follows.

Note: In this experiment, OS: centos6 64bit.

Although there are a lot of documents on the network that integrate nginx and asp.net in windows, it has not been tested successfully in windows. All of the following experiments are performed in linux. Nginx has been installed successfully and runs as follows:

 

The integration of nginx and asp.net is not implemented through the reverse proxy function of nginx, nor through IIS provided by windows, but through fastcgi_pass to process asp.net, then, submit the processed result to nginx. To put it bluntly, nginx is used as a web server.

To integrate Nginx with asp.net, perform the following steps:

1. mono installation

2. xsp installation

3. Integrate nginx with asp.net

4. Test the integration effect

1. Install mono

To enable linux to support asp.net, we must install the mono and xsp packages.

Mono software package is a cross-platform. NET runtime environment developed by Novell.

Currently, mono-3.10.0.tar.bz2 is the latest software package for monoworkflow. We can use this website at http://download.mono-project.com/sources/mono /. Download and upload it to the centos server. As follows:

Scp mono-3.10.0.tar.bz2:/root

 

In addition to the mono-3.10.0.tar.bz2 package, we also need to install xsp.

Xsp is a small. Net Web server, which can be used as a Web server, and the fastcgi-mono-server2/4 can also be run as fastcgi of nginx.

The latest xspsoftware package is xsp-2.10.2.tar.bz2. We can use this URL at http://download.mono-project.com/sources/xsp /. Download and upload it to the centos server. As follows:

Scp xsp-2.10.2.tar.bz2:/root

 

First, decompress and install mono. The mono software package is relatively large and the decompression speed is about 70 MB. As follows:

Tar-xvf mono-3.10.0.tar.bz2

 

 

After decompression, enter the decompression Directory of the mono package, as shown below:

 

 

Before installing mono, we need to install the related software packages as follows:

Yum install gcc-c ++ glibc-devel glib

 

 

Configure mono as follows:

./Configure

 

 

As shown in the preceding figure, mono supports. net2.0 to. net4.5.

After the configuration, make will compile mono as follows:

 

Mono's make compilation process is slow and requires patience. In this process, we can see that there are a lot of files that have ended with lo. These files are the target files compiled using libtool.

 

 

After Make is compiled, we will start to formally install mono, as shown below:

Make install

 

During the installation process, if you observe carefully, you will see that mono is installed in the/usr/local/lib/mono directory by default. The default./configure software is usually under/user/local. Because it is a library, the file is under/user/local/lib.

Of course, you can also run the./configure-help command during compilation. As follows:

 

 

From the figure above, we can see that the default installation location of Linux is indeed the same as what we mentioned above.

The figure below shows a screenshot of mono installation:

 

After installation, we can view the mono installation location based on the information provided during installation. As follows:

 

 

As shown in the preceding figure, mono is installed in the/usr/local/lib directory.

Now we can run the mono-V command to check whether mono is successfully installed. As follows:

Mono-V

 

The information shown in the preceding figure indicates that mono has been installed successfully.

Note: The mono Command is located in the/usr/local/bin/mono path, as shown below:

 

At the same time, the path/usr/local/bin already exists in the system environment variable. As follows:

Echo $ PATH

 

II. xsp installation

After mono is installed, we also need to install the small. NET web server XSP. Unzip and install xsp as follows:

Tar-xvf xsp-2.10.2.tar.bz2

 

Configure xsp as follows:

./Configure

 

However, the system prompts the following error:

 

Why is an error prompted?

Because the C # program must be dynamically linked to the database during execution, it must be added to the environment variable. In addition, some mono compilers of the link Library need to use the pkgconfig tool internally. Therefore, you must configure the PKG_CONFIG_PATH environment variable. The pkgconfig tool is located in the path/usr/local/lib/pkgconfig. As follows:

 

What we need to do now is to configure the path of the pkgconfig tool to use the export command, as shown below:

Export PKG_CONFIG_PATH =/usr/local/lib/pkgconfig/

 

After the path of the Pkgconfig tool is set, configure xsp again as follows:

 

As shown in the preceding figure, no error is reported in xsp.

After the xsp configuration is complete, we will compile the software through make as follows:

Make

 

After xsp is compiled, we will officially install xsp as follows:

Make install

 

After xsp is installed, we can check the fastcgi-mono-server2/4 program. As follows:

 

From the above figure, we can see that the fastcgi-mono-server2/4 Command is located under/usr/local/bin.

Note that this command is very important. This command is used to start the xsp. Net web server.

III. Integration of nginx and asp.net

The above is the installation of mono and xsp, and the integration with nginx is started below. Asp.net is integrated with nginx, which is implemented through the nginx virtual host.

Modify the nginx configuration file nginx. conf and 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. aspx index.html index.htm;

Fastcgi_pass 127.0.0.1: 9001;

Include fastcgi_params;

}

}

Note that we have already introduced how nginx and asp.net are integrated. Nginx uses fastcgi_pass to process asp.net requests and then delivers the processed results to nginx. Fastcgi_pass acts as the proxy for xsp web servers.

At the same time, we should also note that the xsp port of the fastcgi_pass proxy is 9001, which can be defined at will, as long as it does not conflict with the port in use in the system.

 

After this file is modified, we also need to modify the file fastcgi_params.

We only need to add two lines of code at the end of the file. As follows:

Fastcgi_param PATH_INFO "";

Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;

 

After the above two files are modified, we will start the xsp web server now. Run the following command:

Fastcgi-mono-server2/applications =/:/ilanni/B .ilanni.com/socket = tcp: 127.0.0.1: 9001 &

Note that/ilanni/B .ilanni.com in this command is the root directory of the Nginx VM. 127.0.0.1: 9001 indicates that xsp uses 127.0.0.1: 9001. & Indicates that the command is run in the background.

 

From the figure above, we can see that the xsp server has been started normally. Now we have an asp.net probe to test it.

 

Now let's access Nginx's virtual host B .ilanni.com, as shown below:

 

As shown in the figure above, we can easily see it. Currently, the asp.net program can be accessed.

IV. Test the integration effect

The screenshot above makes it easy to see. Now Nginx and asp.net are fully integrated. Let's take a look at php integration.

In fact, it should not be said that Nginx is integrated with php, because Nginx supports php and uses fastcgi_pass to proxy php-fpm, and then sends the request result to Nginx.

Now let's create an Nginx virtual host, as shown below:

 

Access the VM a.ilanni.com. As follows:

 

So far, we can see that Nginx now fully supports asp.net and php.

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.