1.安装Nginx依赖库
#安装Nginx的编译环境gcc
yum install gcc-c++
#nginx的http模块使用pcre解析正则表达式所以安装perl兼容的正则表达式库
yum install -y pcre pcre-devel
#nginx使用zlib对http包的内容进行gzip
yum install -y zlib zlib-devel
#nginx不仅支持http协议,还支持https(即在ssl协议上传输http),如果使用了https,需要安装OpenSSL库
yum install -y openssl openssl-devel
2.下载安装包
wget http://nginx.org/download/nginx-1.16.1.tar.gz
tar -zxf nginx-1.16.1.tar.gz
mv nginx-1.16.1 Nginx
mkdir nginx-1.16.1
cd Nginx/
# --with-http_stub_status_module --with-http_ssl_module这个是https支持,需要带上;--with-stream --with-stream_ssl_module是TCP和UDP支持
./configure --prefix=/usr/local/nginx/nginx-1.16.1 --with-http_stub_status_module --with-http_ssl_module --with-stream --with-stream_ssl_module
make
make install
ln -s /usr/local/nginx/nginx-1.16.1 /usr/nginx
3.设置环境变量
vim /etc/profile
# set nginx enviroment
NGINX_HOME=/usr/nginx
PATH=$PATH:$NGINX_HOME/sbin
export NGINX_HOME PATH
source /etc/profile
4.在/etc/init.d/目录建立php-fpm
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# this script create it by ruijie. at 2014.02.26
# if you find any errors on this scripts,please contact ruijie.
# and send mail to ruijie at gmail dot com.
# ruijie.qiao@gmail.com
nginxd=/usr/nginx/sbin/nginx
nginx_config=/usr/nginx/conf/nginx.conf
nginx_pid=/usr/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ] && netstat -tunpl | grep nginx &> /dev/null;then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog!"
$nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog!"
$nginxd -s stop
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/nginx
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog!"
#kill -HUP `cat ${nginx_pid}`
$nginxd -s reload
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|help}"
exit 1
esac
exit $RETVAL