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= 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= 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() {