1.部署前同样先安装所需环境,这里直接继续以下过程,不在多做分步介绍
yum -y install gcc gcc-c++ make libtool zlib zlib-devel pcre pcre-devel openssl openssl-devel autoconf automake
将pcre包上传到服务器内 添加nginx用户 ,并将包解压缩。
useradd -s /sbin/nologin -M www (添加用户)
tar zxf nginx-1.14.1.tar.gz -C /usr/local/src (解压压缩包,解压前先将压缩包拖入)
配置、编译、安装
cd /usr/local/src/nginx-1.14.1
./configure \
--prefix=/usr/local/nginx \
--with-http_ssl_module \
--with-http_dav_module \
--with-http_stub_status_module \
--with-http_addition_module \
--with-http_realip_module \
--with-http_sub_module \
--with-http_flv_module \
--with-http_mp4_module \
--user=www --group=www
make && make install (安装运行)
选项说明
--with-http_dav_module #启用支持(增加PUT,DELETE,MKCOL:创建集合,COPY和MOVE方法)默认关闭,需要编译开启
--with-http_stub_status_module #启用支持(获取Nginx上次启动以来的工作状态)
--with-http_addition_module #启用支持(作为一个输出过滤器,支持不完全缓冲,分部分相应请求)
--with-http_sub_module #启用支持(允许一些其他文本替换Nginx相应中的一些文本)
--with-http_flv_module #启用支持(提供支持flv视频文件支持)
--with-http_mp4_module #启用支持(提供支持mp4视频文件支持,提供伪流媒体服务端支持)
--with-pcre=/usr/local/src/pcre-8.37 #需要注意,这里指的是源码,用#./configure --help |grep pcre查看帮助
2.配置nginx支持php文件
vim /usr/local/nginx/conf/nginx.conf
修改用户为nginx:
改:2 #user nobody;
为:3 user www;
启用PHP支持,参照如下做修改,注意与原配置文件格式对齐
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
3.配置启动脚本
将nginx命令生成软链接到bin目录:
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
生成启动脚本,vim /etc/init.d/nginx(粘贴脚本看完是否有无#)
!/bin/bash
chkconfig: - 99 2
description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
$PROG
;;
stop)
kill -3 $(cat $PIDF)
;;
restart)
$0 stop &> /dev/null
if [ $? -ne 0 ] ; then continue ; fi
$0 start
;;
reload)
kill -1 $(cat $PIDF)
;;
*)
echo "Userage: $0 { start | stop | restart | reload }"
exit 1
esac
exit 0
给予执行权限,加入开机启动
chmod +x /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on
启动命令
nginx 或者 service nginx start