一、首先安装必要的库 nginx 中gzip模块需要 zlib 库,rewrite模块需要 pcre 库,ssl 功能需要openssl库。选定/usr/local为安装目录,以下具体版本号根据实际改变。 1.安装PCRE库 $ cd /usr/local/ $ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz $ tar -zxvf pcre-8.36.tar.gz $ cd pcre-8.36 $ ./configure $ make $ make install 2.安装zlib库 $ cd /usr/local/ $ wget http://zlib.net/zlib-1.2.8.tar.gz $ tar -zxvf zlib-1.2.8.tar.gz $ cd zlib-1.2.8 $ ./configure $ make $ make install 3.安装ssl $ cd /usr/local/ $ wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz $ tar -zxvf openssl-1.0.1j.tar.gz $ ./config $ make $ make install 二、安装nginx $ cd /usr/local/ $ wget http://nginx.org/download/nginx-1.12.2.tar.gz $ tar -zxvf nginx-1.12.2.tar.gz $ cd nginx-1.12.2 $ ./configure --prefix=/usr/local/nginx $ make $ make install 在--prefix后面接以下命令: --with-pcre=/usr/local/pcre-8.36 指的是pcre-8.36 的源码路径。 --with-zlib=/usr/local/zlib-1.2.8 指的是zlib-1.2.8 的源码路径。 三、shell安装脚本 脚本中可以选定版本号,支持库包是以yum方式在线安装的
\#!/bin/bash #-------------------------------------------------------- # Function: Install nginx for CentOS7 # Date: 2018-1-06 # Author: Anwar Wong #-------------------------------------------------------- #Print debug information NGINX\_VER="$?" NGINX\_SOFT="nginx-${NGINX\_VER}.tar.gz" NGINX\_URL="http://nginx.org/download" NGINX\_DIR="/usr/local/nginx" NGINX\_SRC=echo $NGINX\_SOFT| sed 's/.tar.\*//g' NGINX\_YUM="yum install -y" NGINX\_ARG="--user=www --group=www --with-http\_stub\_status\_module --with-http\_ssl\_module" if [$? -eq 0\]; then echo -e "\\033\[32m-----------------\\033\[0m" echo -e "\\033\[32mUsage:{/bin/bash $0 1.2.3|1.12.2}\033[0m" exit 0 fi #Installing dependencies $NGINX\_YUM wget make tar gcc gcc-c++ glibc zlib zlib-devel $NGINX\_YUM perl perl-devel pcre pcre-devel openssl openssl-devel #Downloading wget -c $NGINX\_URL/$NGINX\_SOFT tar -xzf $NGINX\_SOFT cd $NGINX\_SRC #Creating user and group useradd -s /sbin/nologin www #Starting install nginx ./configure --prefix=$NGINX\_DIR/$NGINX\_ARG #Compile nginx make -j4 make -j4 install #Starting Nginx $NGINX\_DIR/sbin/nginx #Show nginx status ps -ef |grep nginx netstat -tnlp |grep nginx 四、启动 $ /usr/local/nginx/sbin/nginx 检查是否启动成功: 打开浏览器访问此机器的 IP,如果浏览器出现 Welcome to nginx! 则表示 Nginx 已经安装并运行成功。 部分命令如下: 重启: $ /usr/local/nginx/sbin/nginx –s reload 停止: $ /usr/local/nginx/sbin/nginx –s stop 测试配置文件是否正常: $ /usr/local/nginx/sbin/nginx –t 强制关闭: $ pkill nginx -----------未完待续-------------

标签: none

相关文章推荐

添加新评论,含*的栏目为必填