Nginx installation in centos is summarized. The source code package wget is first sent to the server from the official website, through some nginx configuration, compilation, and finally service registration./etc/init.d
, You can use System V,service
Command to control nginx.
Download source code package
Go to the nginx official website to download it. You can pull it directly on the server by wget, http://nginx.org/en/download.html, and selectStable version
Version
Prerequisites
Nginx compilation requires several prerequisites,GCC
,PCRE
,zlib
,OpenSSL
GCC
This command is used to compile nginx. It is executed at http://zh.wikipedia.org/wiki/gcc.gcc
To test whether GCC has been installed. Installation instructions:
yum install gcc
PCRE
Is nginx rewrite core modules need regular expression support, http://www.pcre.org/
yum install pcre pcre-devel
zlib
Provide compression algorithm, http://zh.wikipedia.org/wiki/Zlib
yum install zlib zlib-devel
OpenSSL
Open-source SSL/TLS Module
yum install openssl openssl-devel
Module configuration
Nginx many modules, core modules are enabled by default, such as gzip, rewrite, etc., need to select the configuration to enable and disable, the official module description http://wiki.nginx.org/Modules
Currently, I only need to enable HTTPS access and register an independent user for nginx in advance, such as a userwww
, Throughconfigure
To configure
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module
Compile
make
After compilation, install and automatically copy some files to some specific directories of the configuration.
make install
You can send some parameters to the nginx binary execution file to return some information, such as nginx version information and manually enabled module information.
<prefix>/sbin/nginx -V## nginx version: nginx/1.4.6## built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC) ## TLS SNI support enabled## configure arguments: --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module
Register System Service, System V script
Script http://www.rackspace.com/knowledge_center/article/centos-adding-an-nginx-init-script
Create a file nginx in/etc/init. d/and configure its executable permissions.chmod +x ./nginx
, Modify some prefix-related paths in the script according to your own situation.
chkconfig nginx on
In this way, nginx can be automatically started as the system starts.service
To manage nginx, suchservice nginx stop
Install nginx on centos