安装Nginx
1) 编译安装前准备
yum install -y gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
2) 安装Nginx(Stable version:最新稳定版)
1) 下载
cd /usr/local/src
wget http://nginx.org/download/nginx-1.14.0.tar.gz
2) 解压
tar -zxvf nginx-1.14.0.tar.gz
3) 进入目录
cd nginx-1.14.0/
4) 配置
./configure --prefix=/usr/local/nginx --pid-path=/run/nginx.pid --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-pcre
5) 编译安装
make && make install
3) 创建nginx启动命令脚本
1) vi /etc/init.d/nginx
#! /bin/bash
# chkconfig: - 85 15
PATH=/usr/local/nginx
DESC="nginx daemon"
NAME=nginx
DAEMON=$PATH/sbin/$NAME
CONFIGFILE=$PATH/conf/$NAME.conf
PIDFILE=$PATH/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
$DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}
do_stop() {
$DAEMON -s stop || echo -n "nginx not running"
}
do_reload() {
$DAEMON -s reload || echo -n "nginx can't reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
do_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
do_stop
echo "."
;;
reload|graceful)
echo -n "Reloading $DESC configuration..."
do_reload
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME"
do_stop
do_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac
exit 0
2)设置执行权限
chmod a+x /etc/init.d/nginx
注册成服务
chkconfig --add nginx
设置开机启动
chkconfig nginx on