1 Nginx Installation Environment
Nginx is a C language development, it is recommended to run on Linux, this tutorial uses Centos6.5 as the installation environment.
Gcc
Installation nginx need to download the source code to compile, compile dependent gcc environment, if there is no GCC environment, need to install GCC:yum install gcc-c++
PCRE
PCRE (perl Compatible Regular Expressions) is a Perl library that includes a Perl-compatible regular expression library. The Nginx HTTP module uses PCRE to parse the regular expression, so the Pcre library needs to be installed on Linux.
Yum install-y pcre Pcre-devel
Note: Pcre-devel is a two-time development library developed using PCRE. Nginx also needs this library.
Zlib
The Zlib library provides a number of ways to compress and decompress, and Nginx uses zlib to gzip the contents of the HTTP package, so you need to install the Zlib library on Linux.
Yum install-y zlib Zlib-devel
Openssl
OpenSSL is a strong Secure Sockets Layer cipher library that includes key cryptographic algorithms, common key and certificate encapsulation management functions, and SSL protocols, and provides a rich set of applications for testing or other purposes.
Nginx not only supports the HTTP protocol, but also supports HTTPS (that is, transmitting HTTP on the SSL protocol), so you need to install the OpenSSL library on Linux.
Yum Install-y OpenSSL Openssl-devel
2. Compiling the installation
Copy the nginx-1.8.0.tar.gz to a Linux server.
---decompression:
TAR-ZXVF NGINX-1.8.0.TAR.GZCD nginx-1.8.0
---Configure
In order to avoid subsequent trouble in the execution ./configure ago
Create TEMP and Nginx directories under/var
./configure--help Query Detailed parameters (refer to the Appendix of this tutorial: Nginx compilation parameters)
The parameters are set as follows:
#使用mkdir命令在/var create temp and Nginx directory
[[email protected] nginx-1.8.0]#./configure--prefix=/usr/local/nginx \ //installation directory --pid-path=/var/run/nginx/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: The temp file directory is specified as/var/temp/nginx on the top, and you need to create a temporary and Nginx directory under/var
Otherwise you will get an error when activating Nginx
Solutions
[[email protected] ~]# mkdir-p/var/tmp/nginx/{client,proxy,fastcgi,uwsgi,scgi}
So in order to avoid trouble, in the execution ./configure ago
Create TEMP and Nginx directories under/var
---compile and install
[[ Email protected] nginx-1.8.0]#make[[email protected] nginx-1.8.0]#make Install
3. Start Nginx
Query Nginx Process:
[[Email protected] sbin]# PS aux |grep nginxroot 6491 0.0 0.0 5028 648? Ss 22:18 0:00 nginx:master process./nginxnobody 6492 0.0 0.1 5232 1300? S 22:18 0:00 nginx:worker processroot 6920 0.0 0.0 6048 788 pts/0 s+ 22:51 0:00 grep nginx
6491 is the process of Nginx main process id,6492 is the process ID of nginx worker process
Note: Execute./nginx start Nginx, here you can specify the Nginx configuration file loaded, as follows:
./nginx-c/usr/local/nginx/conf/nginx.conf
If you do not specify-c,nginx to load the conf/nginx.conf file by default at startup, the address of this file can also be specified when compiling the Nginx installation./configure parameters (--conf-path= pointing to the configuration file (nginx.conf))
4. Stop Nginx
Mode 1, Quick stop:
Cd/usr/local/nginx/sbin./nginx-s stop
This method is equivalent to identifying the Nginx process ID and then using the KILL command to force the kill process.
Mode 2, complete stop ( recommended ):
Cd/usr/local/nginx/sbin./nginx-s quit
This stop step is to wait until the Nginx process finishes processing the task to stop.
5. Restart Nginx
Mode 1, stop and restart (recommended):
The restart of Nginx is equivalent to stop nginx and start Nginx, that is, to execute the Stop command before executing the start command.
As follows:
./nginx-s Quit./nginx
Mode 2, reload the configuration file:
When Nginx configuration file nginx.conf modified, want to let the configuration take effect need to restart Nginx, use-s reload do not have to stop nginx and then start Nginx can be configured in Nginx to take effect, as follows:
./nginx-s Reload
Installing Nginx under CentOS