1. Install nginx 1.1 in advance
Install nginx library package dependencies in centos. The installation command is as follows:
sudo yum groupinstall "DevelopmentTools"sudo yum install pcre pcre-develsudo yum install zlib zlib-develyum install perl-ExtUtils-Embedsudo yum install openssl openssl-devel
1.2 Installation
The most important feature is the modularization Based on HTTP and HTTPS content. The configuration parameter can be as follows:
./configure --prefix=/usr/local/nginx-1.5.13--user=app --group=app --with-http_ssl_module --with-http_realip_module
Install all necessary modules:
./configure --user=app --group=app--with-http_ssl_module --with-http_realip_module --with-http_addition_module--with-http_xslt_module --with-http_image_filter_module--with-http_geoip_module --withhttp_sub_module --with-http_dav_module--with-http_flv_module --withhttp_mp4_module --with-http_gzip_static_module--with-http_random_index_module --with-http_secure_link_module--with-http_stub_status_module --with-http_perl_module--with-http_degradation_module
Use the root user or the administrator user to execute this command.
sudo make & sudo make install
….cp conf/scgi_params '/usr/local/nginx-1.5.13/conf/scgi_params.default'test -f '/usr/local/nginx-1.5.13/conf/nginx.conf' || cp conf/nginx.conf'/usr/local/nginx-1.5.13/conf/nginx.conf'cp conf/nginx.conf '/usr/local/nginx-1.5.13/conf/nginx.conf.default'test -d '/usr/local/nginx-1.5.13/logs' || mkdir -p'/usr/local/nginx-1.5.13/logs'test -d '/usr/local/nginx-1.5.13/logs' || mkdir -p'/usr/local/nginx-1.5.13/logs'test -d '/usr/local/nginx-1.5.13/html' || cp -R html'/usr/local/nginx-1.5.13'test -d '/usr/local/nginx-1.5.13/logs' || mkdir -p'/usr/local/nginx-1.5.13/logs'make[1]: Leaving directory `/home/app/Downloads/nginx-1.5.13'
1.3 Test
To test whether the nginx configuration is correct, run the following command:
Start nginx
#sudo /usr/local/nginx-1.5.13/sbin/nginx
View the http: // localhost page. The result is as follows:
Welcome to nginx!
2. Use commands
After nginx is successfully installed, you need to know the basic commands.
nginx –s stop Stops the daemon immediately (using the TERM signal)nginx –s quit Stops the daemon gracefully (using the QUIT signal)nginx –s reopen Reopens the log filesnginx –s reload Reloads the configuration
Stop the nginx process and enter the following command:
Killall nginx
Test whether the configuration is successful:
[[email protected] sbin]$ sudo/usr/local/nginx/sbin/nginx -t[sudo] password for app:nginx: the configuration file/usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file/usr/local/nginx/conf/nginx.conf test is successful
For more information about nginx commands, enter:
[[email protected]]$ ./nginx -hnginxversion: nginx/1.5.13Usage:nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives] Options: -?,-h : this help -v : show version and exit -V : show version and configure options then exit -t : test configuration and exit -q : suppress non-error messages during configuration testing -ssignal : send signal to a masterprocess: stop, quit, reopen, reload -p prefix : set prefix path (default: /usr/local/nginx/) -c filename : set configuration file (default: conf/nginx.conf) -g directives : set global directives out ofconfiguration file
The following table shows different running levels and their meanings.
After learning about the running level of the system process, we can add nginx to the system service. Create an nginx script in the/etc/init. d directory. For example, the nginx script can be configured as follows:
Bytes ---------------------------------------------------------------------------------------------------
Modify the execution permission.
#sudo chmod +x /etc/init.d/nginx
Restart nginx:
sudo /usr/init.d/nginx reload
Add nginx to the Automatic startup file list:
sudo chkconfig –add nginx
Check the running level of nginx:
[[email protected]~]$ sudo chkconfig --list nginxnginx 0:off 1:off 2:off 3:off 4:off 5:off 6:off