Installation and use of Nginx

Source: Internet
Author: User
Tags openssl library


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://

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
    2. Unzip the pcre-xx.tar.gz package.
    3. Go to unzip directory and execute./configure.
    4. Make & make Install
    5. 1.2. Installing OpenSSL
    6. Gets the OpenSSL compilation installation package, which is available on the current latest version.
    7. Unzip the openssl-xx.tar.gz package.
    8. Go to unzip directory and execute./config.
    9. Make & make Install
    10. 1.3. Installing zlib
    11. Gets the zlib compiled installation package, which can get the current latest version on
    12. Unzip the openssl-xx.tar.gz package.
    13. Go to unzip directory and execute./configure.
    14. Make & make Install
    15. 1.4. Installing Nginx
    16. Get Nginx, you can get the latest version on
    17. Unzip the nginx-xx.tar.gz package.
    18. Go to unzip directory, execute./configure
    19. Make & make Install

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.

Start Nginx

The Nginx startup command is:


-C Set the path to the configuration file, without-nginx the configuration file that automatically loads the default path.

Linux 64-bit installation Nginx error reported following errors

[root @localhost nginx- 1.3 . 0 ]# /usr/local/nginx/sbin/nginx error while loading shared libraries: 1 : cannot open shared object file: No such file or directoryFrom the error seen is the lack of LIB file caused, further review the next [root @localhost nginx- 1.3 . 0 ]# ldd $(which /usr/local/nginx/sbin/nginx) 1 =&gt; ( 0x00007fff4d5ff000 ) 0 =&gt; /lib64/ 0 ( 0x00007fea7e357000 ) 1 =&gt; /lib64/ 1 ( 0x00007fea7e120000 ) 1 =&gt; not found 1 =&gt; /lib64/ 1 ( 0x00007fea7df09000 ) 6 =&gt; /lib64/ 6 ( 0x00007fea7db76000 ) /lib64/ld-linux-x86- 64 .so. 2 ( 0x00007fea7e57d000 ) =&gt; /lib64/ ( 0x00007fea7d913000 ) 2 =&gt; /lib64/ 2 ( 0x00007fea7d70f000 )It can be seen that = not found is not found, enter the/lib64 directory under manual link [root @localhost /]# cd lib64/ [root @localhost lib64]# ln -s 0.0 . 1 1And then start the Nginx and it's OK.

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











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


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.


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;


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


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.


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


< 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://

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;


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


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.


Baidu Encyclopedia: Http://

Fastcgi.conf vs Fastcgi_params:

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: 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.