Installation and use of Nginx

Source: Internet
Author: User
Tags openssl library

Objective

Nginx is a lightweight Web server/reverse proxy server and e-mail (IMAP/POP3) proxy server that is released under a bsd-like protocol. Developed by Russian program designer Igor Sysoev for use in Russian large portals and search engine Rambler (Russian: Рамблер). It is characterized by the possession of less memory, concurrency is strong, in fact, nginx concurrency is actually in the same type of Web server performance better. (Baidu Encyclopedia-Http://www.dwz.cn/x32kG)

1.Nginx Installation

The environment I am using is 64-bit Ubuntu 14.04. Nginx relies on the following modules:

L gzip module requires zlib library

L Rewrite module requires Pcre library

L SSL function requires OpenSSL library

1.1. Installing Pcre
    1. Get Pcre Compile the installation package and get the current latest version on http://www.pcre.org/
    2. Unzip the pcre-xx.tar.gz package.
    3. Go to unzip directory and execute./configure.
    4. Make & make Install
    5. Gets the OpenSSL compilation installation package, which is available on http://www.openssl.org/source/for the current latest version.
    6. Unzip the openssl-xx.tar.gz package.
    7. Go to unzip directory and execute./config.
    8. Make & make Install
    9. Gets the zlib compiled installation package, which can get the current latest version on http://www.zlib.net/.
    10. Unzip the openssl-xx.tar.gz package.
    11. Go to unzip directory and execute./configure.
    12. Make & make Install
    13. Get Nginx, you can get the latest version on http://nginx.org/en/download.html.
    14. Unzip the nginx-xx.tar.gz package.
    15. Go to unzip directory, execute./configure
    16. Make & make Install
1.2. Install openssl1.3. Install zlib1.4. Install Nginx

If the above dependent modules cannot be found during installation, use--with-openssl=<openssl_dir> 、--with-pcre=<pcre_dir> 、--with-zlib=<zlib_dir> Specifies a dependent module directory. If installed, the path here is the installation directory, if not installed, this path is the compiled installation package path, Nginx will execute the module's default compilation installation.

After you start Nginx, enter http://localhost in the browser to verify that the installation started successfully.

2.Nginx Configuration

After the installation is complete, the configuration directory conf has the following configuration files, filtering out the Xx.default configuration:

[Email protected]:/opt/nginx-1.7.7/conf$ tree |grep-v Default

.

├──fastcgi.conf

├──fastcgi_params

├──koi-utf

├──koi-win

├──mime.types

├──nginx.conf

├──scgi_params

├──uwsgi_params

└──win-utf

except nginx.conf . , the rest of the configuration files, generally only need to use the default provided .

2.1.nginx.conf

Nginx.conf is the master configuration file, and the default configuration removes the comment after it as shown in the following:

L Worker_process Indicates the number of worker processes, typically set to the CPU's number of cores

L Worker_connections indicates the maximum number of connections per worker process

L server{} block defines a virtual host

N Listener Listening Port

N server_name Monitor domain name

N location{} is used to configure a matching URI, which is "/uri/" in the syntax. Location/{} matches any query because all requests start with/.

U root Specifies the resource lookup path for the corresponding URI, where the HTML is a relative path and the full path is/opt/opt/nginx-1.7.7/html/

U index Specifies the name of the index file on the first page and can be configured with multiple, separated spaces. If there are multiple, look in the configuration order.

From the configuration can be seen, nginx monitoring 80 port, the domain name is localhost, followed by the path to the HTML folder (my installation path is/opt/nginx-1.7.7, so/opt/nginx-1.7.7/html), The default index file is index.html, index.htm, and server errors are redirected to the 50x.html page.

You can see that/opt/nginx-1.7.7/html/has the following files:

[Email protected]:/opt/nginx-1.7.7/html$ ls

50x.html index.html

This is also the above in the browser input http://localhost, can display the Welcome page reason. The/opt/nginx-1.7.7/html/index.html file is actually accessed.

2.2.mime.types

file name extension and file type mapping table, Nginx based on the mapping relationship, set the HTTP Content-type of the request response header values . When the mapping table is not found, the default value specified by Default-type in nginx.conf is used. For example, the specified default-type in the default configuration is Application/octet-stream.

Include Mime.types;

Default_type Application/octet-stream;

Default

The following section mime.types defines the file extension and file type mapping relationship, the complete self-view:

2.3.fastcgi_params

Nginx configuration fastcgi will invoke the fastcgi_params configuration file to pass server variables when parsing, so that the values of these variables can be obtained in CGI. The following variables are passed by default:

The role of these variables can be seen from their naming.

2.4.fastcgi.conf

In contrast to the fastcgi.conf and fastcgi_params files, you can see only the following differences:

[Email protected]:/opt/nginx-1.7.7/conf$ diff fastcgi.conf Fastcgi_params

2d1

< Fastcgi_param script_filename $document _root$fastcgi_script_name;

That is, fastcgi.conf only more than fastcgi_params a line "Fastcgi_param script_filename $document _root$fastcgi _script_name;"

Originally only Fastcgi_params file, fastcgi.conf is Nginx 0.8.30 (released:15th of December 2009) was introduced. The main problem is to solve the following problems (refer to: Http://www.dwz.cn/x3GIJ):

Originally Nginx only Fastcgi_params, and later found that many people in the definition of script_filename use hard-coded way. For example, Fastcgi_param script_filename /var/www/foo$fastcgi _script_name. The fastcgi.conf is then introduced to standardize usage.

However, this raises the question of why it is necessary to introduce a new configuration file instead of modifying the old one. This is because the fastcgi_param instruction is an array type, and the same as the normal instruction: The inner layer replaces the outer layers, and the ordinary instruction is different: when used in the same class multiple times, is added instead of replaced. In other words, if you define two script_filename at the same level, then they will be sent to the backend, which may cause some potential problems, and in order to avoid such situations, a new configuration file is introduced.

So it is no longer recommended that you use the following method (search for a large number of articles on the web, and nginx.conf's default configuration is also used this way):

Fastcgi_param script_filename $document _root$fastcgi_script_name;

Include Fastcgi_params;

and use the newest way:

Include fastcgi.conf;

2.5.uwsgi_params

As with Fastcgi_params, which server variables are passed , only the prefixes are different, starting with Uwsgi_param rather than Fastcgi_param.

2.6.scgi_params

As with Fastcgi_params, which server variables are passed , only the prefixes are different, starting with Uwsgi_param rather than Fastcgi_param.

2.7.koi-utf, Koi-win, Win-utf

All three files are associated with the Encoding transformation mapping file, which is used to convert one encoding to another encoding when the content is output to the client.

Koi-win:charset_map Koi8-r <--> windows-1251

Koi-utf:charset_map Koi8-r <--> Utf-8

Win-utf:charset_map windows-1251 <--> Utf-8

Koi8-r is a Cyrillic 8-bit code for use in Russian and Bulgarian languages. Before Unicode was popular, Koi8-r was the most widely used Russian code, with a high utilization rate even from ISO/IEC 8859-5. These 3 files exist because the author is a Russian.

3. RELATED LINKS

http://www.pcre.org/

http://www.openssl.org/source/

http://www.zlib.net/

http://nginx.org/

Baidu Encyclopedia: Http://www.dwz.cn/x32kG

Fastcgi.conf vs Fastcgi_params:http://www.dwz.cn/x3gij

Wu Qin
Source: http://www.cnblogs.com/skynet/
This article is based on the attribution 2.5 China mainland license agreement, which is reproduced, interpreted or used for commercial purposes, but must retain the attribution Wu Qin (including links) herein.

Installation and use of Nginx

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.