centos 7.4 安装Nginx-1.10.3
$ yum install gcc-c++
$ yum install pcre pcre-devel
$ yum install zlib zlib-devel
$ yum install openssl openssl-devel
mkdir -p /usr/local/Nginx #创建一个安装目录
cd /usr/local/Nginx #切换到创建好的目录
wget http://nginx.org/download/nginx-1.10.3.tar.gz #下载安装包
tar -zxvf Nginx-1.10.3.tar.gz #解压
cd Nginx-1.10.3 #到解压目录下编译
./configure --prefix=/usr/local/Nginx --with-pcre --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module
#在编译的时候可能遇到以下报错:
/configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option,or install the PCRE library into the system,or build the PCRE library
statically from the source with Nginx by using --with-pcre=<path> option. #没有安装pcre-devel
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules,or install the OpenSSL library
into the system,or build the OpenSSL library statically from the source
with Nginx by using --with-openssl=<path> option #没有安装openssl-devel
#针对上诉的报错情况,执行下面的安装命令,然后就可以正常编译
yum -y install pcre-devel openssl openssl-devel
make && make install #安装
vim /etc/init.d/Nginx #在 /etc/init.d下创建一个Nginx文件,并输入以下代码
#!/bin/bash
#chkconfig: 2345 80 90
#description:auto_run
PATH=/usr/local/Nginx
DESC="Nginx server"
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
chmod a+x /etc/init.d/Nginx #给执行权限
chkconfig Nginx on #设置开机启动
systemctl start Nginx.service #启动Nginx服务
systemctl stop Nginx.service #停止Nginx服务
systemctl restart Nginx.service #重启Nginx服务
systemctl reload Nginx.service #重新读取Nginx配置(这个最常用,不用停止Nginx服务就能使修改的配置生效)
原文链接:https://www.f2er.com/centos/374804.html