Preface:
First introduce Nginx:
Nginx is a lightweight Web server/reverse proxy server and e-mail (IMAP/POP3) proxy server that is released under a bsd-like protocol. 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.
Specific installation details are described below:
1. Install the Dependencies and Software toolkit before installing Nginx: (If the system has a toolkit that ignores this step, you can enter a command at the command line to test whether the command is available)
(1) Install make:
# yum-y Install gcc automake autoconf libtool make
(2) Installation g++:
# yum Install gcc gcc-c++
Other command kits, such as tar, do not have a self-download installation.
2. Install development team and dependent software packages (development tools, server platform development)
# yum Groupinstall-y "Development Tools" "Server Platform Development"
# yum Install-y openssl-devel Pcre-devel
3. Start installing Nginx:
First add the user Nginx, to run the Nginx service process:
# groupadd-r Nginx
# Useradd-r-G Nginx
Then use wget to download the Nginx compressed package directly from the Internet:
# yum Install wget
# wget http://nginx.org/download/nginx-1.4.7.tar.gz
After decompression, compile: Enter the directory first
# Tar XF nginx-1.4.7.tar.gz
# CD nginx-1.4.7
Then start compiling and installing:
# ./Configure--prefix=/usr--sbin-path=/usr/sbin/Nginx--conf-path=/etc/nginx/nginx.conf--error-log-path=/var/log/nginx/Error.log--http-log-path=/var/log/nginx/Access.log--pid-path=/var/run/nginx/Nginx.pid--lock-path=/var/lock/Nginx.lock--user=Nginx--group=Nginx--with-Http_ssl_module--with-Http_flv_module--with-Http_stub_status_module--with-Http_gzip_static_module--http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/Uwsgi--http-scgi-temp-path=/var/tmp/nginx/scgi--with-pcre
And then:
# Make && make install
4. Provide SYSV init script for Nginx
Create a new file/etc/rc.d/init.d/nginx with the following content:
#!/bin/SH# # Nginx-This script starts and stops the Nginx daemon## chkconfig:- - the# Description:nginx is an HTTP (s) server, HTTP (s) reverse # Proxy and IMAP/POP3 proxy server# processname:nginx# config:/etc/nginx/nginx.conf# config:/etc/sysconfig/nginx# pidfile:/var/run/nginx.pid# SourcefunctionLibrary:/etc/rc.d/init.d/functions# Source Networking configuration:/etc/sysconfig/network# Check that networking are up. [ "$NETWORKING"="No"] && exit0Nginx="/usr/sbin/nginx"Prog=$(basename$nginx) Nginx_conf_file="/etc/nginx/nginx.conf"[ -f/etc/sysconfig/nginx] &&. /etc/sysconfig/NginxLockfile=/var/lock/subsys/Nginxmake_dirs () {# MakeRequired Directories User= ' Nginx-v2>&1|grep "Configure arguments:"|sed 's/[^*]*--user=[]∗.*/\1/g' -`Options= ' $nginx-V2>&1|grep 'Configure arguments:'` forOptinch$options; Do if[ `Echo$opt |grep '. *-temp-path'` ]; Thenvalue=`Echo$opt |Cut-D"="-F2` if[!-D"$value"]; Then # Echo "Creating"$valuemkdir-P $value &&Chown-R $user $valuefi fi Done}start () {[-X $nginx] | | Exit5 [ -F $NGINX _conf_file] | | Exit6Make_dirsEcho-N $"starting $prog:"Daemon $nginx-c $NGINX _conf_file retval=$?Echo[$retval-eq0] &&Touch$Lockfilereturn $retval}stop () {Echo-N $"stopping $prog:"Killproc $prog-QUIT retval=$?Echo[$retval-eq0] &&RM-F $Lockfilereturn $retval}restart () {configtest|| Return $?StopSleep 1start}reload () {configtest|| Return $?Echo-N $"Reloading $prog:"Killproc $nginx-HUP RETVAL=$?Echo}force_reload () {restart}configtest () {$nginx-T-C $NGINX _conf_file}rh_status () {status $prog}rh_status_q () {rh_status>/dev/NULL 2>&1} Case " $" inchstart) Rh_status_q&& exit0 $1 ;; Stop) Rh_status_q|| Exit0 $1 ;; Restart|configtest) $1 ;; Reload) Rh_status_q|| Exit7 $1 ;; Force-reload) force_reload;; status) Rh_status;; Condrestart|try-restart) rh_status_q|| Exit0 ;; *) Echo$"Usage: $ {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"Exit2Esac
View Code
Then give execute permission for this script:
# chmod +x/etc/rc.d/init.d/nginx
Add to the service management list and let it boot automatically:
# chkconfig--add Nginx
# chkconfig Nginx on
5. Add environment variables and test
# yum Install vim
# vim/etc/profile.d/nginx.sh
Export path=/usr/local/nginx/sbin/: $PATH
Then start the service and test:
# service Nginx Start
Enter the server IP address on the website: http://172.16.16.173/
6, the PHP configuration into the human nginx:
First configure the Nginx nginx.conf file:
Enter under Terminal: # Find/-name nginx.conf
Locate the nginx.conf configuration file and use Vim to enter the modification: (yum installs vim download and install if no VIM is available)
Then add the following content to the server:
Location ~ \.php$ { root /usr/html; Fastcgi_pass 127.0. 0.1:9000; Fastcgi_index index.php; Fastcgi_param script_filename $document _root$fastcgi_script_name; Include fastcgi_params; }
The yellow section is a web-hosted directory that can be accessed directly in the browser.
also note that the PHP must be compiled to ensure that the system has LIBXML2 and Libxml2-dev both packages, because PHP by default will compile XML functionality, so XML support is essential.
So use: # yum install LIBXML2
# yum Install Libxml2-dev download installs the dependent package.
Then enter the/usr/html directory, vim test1.php, for editing:
<? PHP Echo "TEST by Still"; Phpinfo ();? >
To restart the Nginx service:
# service Nginx Restart
Then view the results in the browser:
Installation and configuration of Nginx under CentOS