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
- Get Pcre Compile the installation package and get the current latest version on http://www.pcre.org/
- Unzip the pcre-xx.tar.gz package.
- Go to unzip directory and execute./configure.
- Make & make Install
- 1.2. Installing OpenSSL
- Gets the OpenSSL compilation installation package, which is available on http://www.openssl.org/source/for the current latest version.
- Unzip the openssl-xx.tar.gz package.
- Go to unzip directory and execute./config.
- Make & make Install
- 1.3. Installing zlib
- Gets the zlib compiled installation package, which can get the current latest version on http://www.zlib.net/.
- Unzip the openssl-xx.tar.gz package.
- Go to unzip directory and execute./configure.
- Make & make Install
- 1.4. Installing Nginx
- Get Nginx, you can get the latest version on http://nginx.org/en/download.html.
- Unzip the nginx-xx.tar.gz package.
- Go to unzip directory, execute./configure
- 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:
/usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx.conf
-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: libpcre.so.
1
:
cannot open shared object file: No such file or directory
From 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)
linux-vdso.so.
1
=> (
0x00007fff4d5ff000
)
libpthread.so.
0
=> /lib64/libpthread.so.
0
(
0x00007fea7e357000
)
libcrypt.so.
1
=> /lib64/libcrypt.so.
1
(
0x00007fea7e120000
)
libpcre.so.
1
=> not found
libz.so.
1
=> /lib64/libz.so.
1
(
0x00007fea7df09000
)
libc.so.
6
=> /lib64/libc.so.
6
(
0x00007fea7db76000
)
/lib64/ld-linux-x86-
64
.so.
2
(
0x00007fea7e57d000
)
libfreebl3.so => /lib64/libfreebl3.so (
0x00007fea7d913000
)
libdl.so.
2
=> /lib64/libdl.so.
2
(
0x00007fea7d70f000
)
It can be seen that libpcre.so.1 = not found is not found, enter the/lib64 directory under manual link
[root
@localhost
/]# cd lib64/
[root
@localhost
lib64]# ln -s libpcre.so.
0.0
.
1
libpcre.so.
1
And 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 . ├──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
Installation and use of Nginx