Install Nginx in Linux and Nginx in Linux
1. What is Nginx?
Nginx ("engine x") is a high-performance HTTP and reverse proxy server and an IMAP/POP3/SMTP server.
Many large websites use nginx for reverse proxy, which is widely used.
Nginx is a high-performance http server/reverse proxy server and email (IMAP/POP3) proxy server. Developed by Russian programmer Igor Sysoev, the official test nginx can support 50 thousand concurrent connections, and its cpu, memory, and other resources are very low and run very stably.
2 application scenarios
1. the http server can be used as an http server for static Web pages.
2. Configure the virtual machine.
A domain name can be bound to multiple ip addresses. You can forward requests to servers running on different ports based on different domain names.
3. reverse proxy and Server Load balancer. Forward requests to different servers.
3 installation and configuration
Download 3.1
Http://nginx.org/
The last stable version is 1.8.0. There are two versions: windows and linux. All production environments use the linux version.
3.2 Installation
3.2.1 environment requirements
Nginx is developed in C language and is recommended to run on linux. In this tutorial, Centos6.4 is used as the installation environment.
N gcc
To install nginx, you must first compile the source code downloaded from the official website. The compilation depends on the gcc environment. If there is no gcc environment, you must install gcc: yum install gcc-c ++.
N PCRE
PCRE (Perl Compatible Regular Expressions) is a Perl library, including a perl-Compatible Regular Expression Library. The http module of nginx uses pcre to parse regular expressions. Therefore, you need to install the pcre Library on linux.
Yum install-y pcre-devel
Note: pcre-devel is a secondary development library developed using pcre. Nginx also needs this library.
N zlib
The zlib library provides many compression and decompression methods. nginx uses zlib to perform gzip on the http package content. Therefore, you need to install the zlib library on linux.
Yum install-y zlib-devel
N openssl
OpenSSL is a powerful secure socket-layer cryptographic library that includes major cryptographic algorithms, common keys, certificate encapsulation management functions, and SSL protocols, and provides a wide range of applications for testing or other purposes.
Nginx not only supports http protocol, but also https (Transmission of http over ssl protocol). Therefore, you need to install the openssl library in linux.
Yum install-y openssl-devel
3.2.2 compilation and Installation
Step 1: Upload the nginx source code package to the linux Server
Step 2: extract the source code package. Tar-zxf nginx-1.8.0.tar.gz
Step 3: Enter the nginx-1.8.0 folder. Use the configure command to create makefile.
Step 4: set parameters as follows:
./Configure \
-- Prefix =/usr/local/nginx \
-- Pid-path =/var/run/nginx. pid \
-- Lock-path =/var/lock/nginx. lock \
-- Error-log-path =/var/log/nginx/error. log \
-- Http-log-path =/var/log/nginx/access. log \
With-http_gzip_static_module \
-- Http-client-body-temp-path =/var/temp/nginx/client \
-- Http-proxy-temp-path =/var/temp/nginx/proxy \
-- Http-fastcgi-temp-path =/var/temp/nginx/fastcgi \
-- Http-uwsgi-temp-path =/var/temp/nginx/uwsgi \
-- Http-scgi-temp-path =/var/temp/nginx/scgi
Note: Specify the temporary file directory as/var/temp/nginx. Create the temp and nginx directories under/var.
Step 5: make
Step 6 make install
3.3 enable and disable Nginx
3.3.1 start
There is a sbin directory under the nginx directory and an nginx executable program under the sbin directory.
./Nginx
3.3.2 disable nginx
Close the command: Find the nginx process kill.
./Nginx-s stop
Exit command:
./Nginx-s quit
After the program is executed, we recommend that you use this command.
3.3.3 dynamically load the configuration file
./Nginx-s reload
You can update the configuration file without disabling nginx.