CentOS 7 部署 nginx-1.14.2

参考:http://www.linuxe.cn/post-168.html

链接:https://pan.baidu.com/s/1NzHIY7mYgHJ6yMF_rdd0ZQ
提取码:n8o9

下载地址:http://nginx.org/en/download.html

1、Mainline version:Mainline 是 Nginx 目前主力在做的版本,可以说是开发版
2、Stable version:最新稳定版,生产环境上建议使用的版本
3、Legacy versions:遗留的老版本的稳定版

1、在安装Nginx之前需要确保系统里已经安装好相关环境:pcre库(提供正则表达式和Rewrite模块的支持)、zlib库(提供Gzip压缩)、openssl(提供ssl支持),如果没有安装的话,用Yum来安装这些依赖环境即可,不需要额外编译:

yum  install  pcre  pcre-devel  openssl  openssl-devel  zlib  zlib-devel gcc-c++ -y

2、为Nginx创建好用户和组,后续编译会用上

groupadd nginx
useradd -s /sbin/nologin -g nginx nginx

3、配置、编译

./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--add-module=../ngx_cache_purge-2.3 \
--with-http_ssl_module \ --with-http_flv_module \ --with-http_mp4_module \ --with-http_gzip_static_module \ --with-http_stub_status_module make && make install
--add-module=../ngx_cache_purge-2.3 \    #后边配置缓存时用到,需要指定ngx_cache_purge-2.3的路径
如果./configure配置出错后
下载
ngx_cache_purge-2.3:http://labs.frickle.com/nginx_ngx_cache_purge

4、编译安装完成后会在指定的安装目录创建以下目录:

prefix/sbin :  Nginx的启动脚本,也可以用该脚本做一系列检查工作
prefix/conf :  配置文件存放的目录
prefix/logs :  日志文件目录
prefix/html :  默认的网页文件存放目录
 /usr/local/nginx/sbin/nginx  -t  #检查配置文件是否有错
 /usr/local/nginx/sbin/nginx  -v   #查看Nginx版本
 /usr/local/nginx/sbin/nginx  -V  #查看编译Nginx时的选项

启动Nginx:

/usr/local/nginx/sbin/nginx
#!/bin/bash
# chkconfig: - 99 2
# description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
        start)
        $PROG
        ;;
        stop)
        kill -3 $(cat $PIDF)
        ;;
        restart)
        $0 stop &> /dev/null
        if [ $? -ne 0 ] ; then continue ; fi
        $0 start
        ;;
        reload)
        kill -1 $(cat $PIDF)
        ;;
        *)
        echo "Userage: $0 { start | stop | restart | reload }"
        exit 1
esac
exit 0
chkconfig --add nginx
posted @ 2018-05-28 13:29  linuxws  阅读(302)  评论(0编辑  收藏  举报