###centos 7.4 安装nginx-1.10.3###

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 #安装

安装完成之后把Nginx添加成系统服务

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 --add Nginx #注册成服务

chkconfig Nginx on #设置开机启动

添加成系统服务之后可以使用以下命令控制Nginx服务

systemctl start Nginx.service #启动Nginx服务

systemctl stop Nginx.service #停止Nginx服务

systemctl restart Nginx.service #重启Nginx服务

systemctl reload Nginx.service #重新读取Nginx配置(这个最常用,不用停止Nginx服务就能使修改的配置生效)

相关文章

Centos下搭建性能监控Spotlight
CentOS 6.3下Strongswan搭建IPSec VPN
在CentOS6.5上安装Skype与QQ
阿里云基于centos6.5主机VPN配置
CentOS 6.3下配置multipah
CentOS安装、配置APR和tomcat-native