CentOS7-Nginx编译安装

http://flowsnow.net/2017/03/30/CentOS7%E4%B8%8ANginx%E7%BC%96%E8%AF%91%E5%AE%89%E8%A3%85/

安装编译环境

yum -y install gcc automake autoconf libtool make
yum install gcc gcc-c++

安装pcre

pcre(Perl Compatible Regular Expressions): perl 兼容的正则表达式库。

以下各编译安装的源码包均放在/usr/local/src下,Nginx依赖pcre是为了重写rewrite。

从ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/下载pcre包,不宜太新,推荐使用pcre8.39或8.40,太新的pcre版本Nginx不支持。

cd /usr/local/src
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz
tar -zxvf pcre-8.39.tar.gz
cd pcre-8.39
./configure
make
make install

安装zlib

zlib是为了Nginx压缩

从http://zlib.net/出下载当前最新源码http://zlib.net/zlib-1.2.11.tar.gz

cd /usr/local/src
wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make
make install

安装ssl

cd /usr/local/src
wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz
tar -zxvf openssl-1.0.1t.tar.gz
cd openssl-1.0.1t
./config    # 不是./Configure
make
make install

安装Nginx

Nginx 一般有两个版本,分别是稳定版和开发版,您可以根据您的目的来选择这两个版本的其中一个,下面是把 Nginx 安装到 /usr/local/nginx 目录下的详细步骤:

cd /usr/local/src
wget http://nginx.org/download/nginx-1.10.2.tar.gz
tar -zxvf nginx-1.10.2.tar.gz
cd nginx-1.10.2
./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.39 --with-zlib=/usr/local/src/zlib-1.2.11 --with-openssl=/usr/local/src/openssl-1.0.1t --with-http_v2_module --with-ipv6
make
make install

--with-pcre=/usr/local/src/pcre-8.39 指的是pcre-8.39 的源码路径。
--with-zlib=/usr/local/src/zlib-1.2.11 指的是zlib-1.2.11 的源码路径。
--with-openssl=/usr/local/src/openssl-1.0.1t指的是openssl-1.0.1t 的源码路径。
--with-http_v2_module 启用 https,时如需使用 http/2 协议,则会依赖ngx_http_v2_module模块,可以使用--with-http_v2_module配置参数来启用。
--with-ipv6 启用IPV6

开机自启动nginx

http://www.jianshu.com/p/b5fa86d54685

[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/nginx -c /usr/local/nginx/nginx.conf
ExecReload=/usr/local/nginx/nginx -s reload
ExecStop=/usr/local/nginx/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl start nginx.service              #启动nginx服务
systemctl status nginx.service             #查看服务当前状态
systemctl restart nginx.service           #重新启动服务
systemctl list-units --type=service        #查看所有已启动的服务

你可能感兴趣的:(CentOS7-Nginx编译安装)