Nginx for mono

Source: Internet
Author: User
Tags openssl library

To deploy a website on Linux, you must first install the web server software. IIS can only be used on windows. You can select the famous Apache and ngnix. This article describes how to install, configure, and use nginx to run a simple Asp.net website.

Nginx

Nginx (engine X) is a high-performance WEB server. Due to its stability, rich functions, and low resource consumption, many websites have already used it for deployment (many large Chinese companies have begun to use nginx to replace Apache. After all, lamp is too systematic ).

Nginx Installation

This article will start from the source code to install nginx with the latest version 1.2.0. All installation processes are carried out in the Ubuntu operating system.

First download the source code:

 wget http://nginx.org/download/nginx-1.2.0.tar.gz

Decompress the package

tar -zxv -f nginx-1.2.0.tar.gz

Go to the decompressed directory and execute

./configure

The PCRE Library is not installed.

Install the PCRE Library using the apt-Get install libpcre3 libpcre3-dev command

Run./configure again to find the lack of HTTP gzip Module

Run apt-Get install libssl-Dev to install the corresponding module.

Run./configure again

 

Then run

makemake install

In this way, nginx is installed, which is installed under/usr/local/nginx by default.

Run the following command to start nginx

/usr/local/nginx/sbin/nginx

 

Test nginx

Nginx is started with the deamon process by default. Run the following command to test whether the startup is successful:

curl -i http://localhost/

After successful installation, the following results are displayed:

If the above information appears, congratulations on the successful installation of nginx.

To stop running nginx, run the following command:

/usr/local/nginx/sbin/nginx -s stop
Configure nginx

The nginx configuration file is a plain text file. The main configuration file is placed in the conf folder under the installation directory by default. Conf contains many configuration files, including nginx. conf as the main configuration file. The configuration file is organized as a block. Each "{}" and its content represent a block. the block can be divided into several levels. The main command in the configuration file is located at the highest level. The main layer can have events, HTTP, and other levels, and the HTTP layer contains the server layer, server block: Server block can be divided into location layers, and a server block can contain multiple location blocks.

 

Open the configuration file and add it in the HTTP configuration block:

include /usr/local/nginx/conf/monotest.conf;

Note: The include command is used to move the configuration of the server section of the VM to a separate file for easy management. The file path is followed by spaces. (Do not forget the Semicolon ";").

The configuration of monotest. conf is as follows:

server{    listen 8001;    server_name localhost;    location   / {    root /home/ubuntu/www/monotest/;    index default.aspx Default.aspx;    fastcgi_index Default.aspx;    fastcgi_pass 127.0.0.1:9001;    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;        include /usr/local/nginx/conf/fastcgi_params;                    }}

Server indicates the virtual host we configured. Listen specifies the port for service listening (usually 80). Here we specify 8001; SERVER_NAME is used to specify the IP address or domain name, separate multiple domain names with spaces;

Location can be used to match URLs. Its syntax is location [= | ~ | ~ * | ^ ~] /Uri /{... }

  • Location/{} matches any query because all requests start. However, regular expression rules are preferentially matched with queries.
  • Location =/{} Only matches/
  • Location ~ * \. (GIF | JPG | JPEG) $ {} is case-insensitive and matches any file ending with GIF, JPG, and JPEG.

Root indicates the site path; index indicates the configured hosts page.

Fastcgi_pass indicates the address used when the FastCGI service is started.

Nginx does not directly support external programs to call or parse (IIS can directly call iaspi for extension) and needs to be called through the FastCGI interface. In Linux, FastCGI uses Socket, so we need to specify the address and bind the port.

Start site

Start nginx and FastCGI services respectively.

Start nginx and enter the/usr/local/nginx/sbin/nginx command at the beginning of the article. If there are no other prompts, the operation is successful (Linux philosophy !), Start FastCGI

su nohup fastcgi-mono-server4 /applications=/:/home/ubuntu/www/monotest/    /socket=tcp:127.0.0.1:9001 &

Nohup... & indicates that the program runs in the background.

Fastcgi-mono-server4 for mono/. Net 4.0 fastcgi-mono-server2 commands for mono/. net2.0.

The/Application parameter is used to specify the ing between the virtual path and the physical path, "/:" indicates ing to the root path, see: http://www.mono-project.com/FastCGI

/Socket specifies the address and port.

After the command is successfully run, a message is displayed:

Nohup: ignore input and append output to "nohup. Out"

Create a simple website

Open monodevelop to create a simple Asp.net website, and select "C #"-"ASP. NET"-"Web application" in the Project template ".

Name the project "monotest ".

The website is only used to test nginx configurations. You do not need to design too much. You can use the default generation of the Project template.

Right-click the project and choose "Tools"> "DeLoy to Web ":

Click the "Edit targets" button, and find "deployment"-"" Web deloyment target "in the left column of the" Project Options "window that appears"

 

Click "add" and fill in the target path to be saved in the pop-up window. Finally, copy the published website to the path specified in the preceding server virtual host configuration.

Running Effect

 

 

Note: after some hard work, it was a successful operation and I still don't know what the performance is. I just clicked some mono-related content in the article. Many configurations of nginx and FastCGI are not described.

Library on which nginx depends:

1. gzip module requires zlib library
2. Rewrite module requires PCRE Library
3. SSL support requires OpenSSL library

 

Reference

Http://wiki.nginx.org/Chs

Http://kb.cnblogs.com/page/98352/

Http://www.cnblogs.com/xiaogangqq123/archive/2011/03/02/1969006.html

Http://blog.sina.com.cn/s/articlelist_1834459124_0_1.html

Http://book.51cto.com/art/201202/314644.htm

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.