CentOS 7编译安装Nginx1.9.0
2016-05-23 20:38
483 查看
原文:https://typecodes.com/web/centos7compilenginx.html
我遇到的问题:在make的时候,遇到如下问题:
make[2]: 进入目录“/home/eastlhu/soft/nginx-1.9.15/pcre-8.38”
CDPATH="${ZSH_VERSION+.}:" && cd . && /bin/sh /home/eastlhu/soft/nginx-1.9.15/pcre-8.38/missing aclocal-1.15 -I m4
/home/eastlhu/soft/nginx-1.9.15/pcre-8.38/missing:行81: aclocal-1.15: 未找到命令
WARNING: 'aclocal-1.15' is missing on your system.
You should only need it if you modified 'acinclude.m4' or
'configure.ac' or m4 files included by 'configure.ac'.
The 'aclocal' program is part of the GNU Automake package:
<http://www.gnu.org/software/automake>
It also requires GNU Autoconf, GNU m4 and Perl in order to run:
<http://www.gnu.org/software/autoconf>
<http://www.gnu.org/software/m4/>
<http://www.perl.org/>
make[2]: *** [aclocal.m4] 错误 127
make[2]: 离开目录“/home/eastlhu/soft/nginx-1.9.15/pcre-8.38”
make[1]: *** [pcre-8.38/.libs/libpcre.a] 错误 2
make[1]: 离开目录“/home/eastlhu/soft/nginx-1.9.15”
make: *** [build] 错误 2
这时候进入pcre目录,执行 autoreconf -ivf
然后继续编译,报了一个:
groff -mandoc -f H -T ps zlib.3 | ps2pdf - zlib.3.pdf
/bin/sh: ps2pdf: 未找到命令
安装
下面开始正文:
该文主要记录如何在CentOS 7.1中编译安装Nginx官方最新的1.9.0版本。由于像Nginx、Mysql和PHP7的的源码都是用C/C++写的,所以自己的CentOS 7.1服务器上必须要安装gcc和g++软件(CentOS 7系列会自带这两个编译软件)。
1 依赖库配置,编译和安装Nginx1.9.0
先创建一个名为nginx且
准备工作做好后,就开始正式配置Nginx-1.9.0的安装明细了。注意,在使用下面这条
配置过程大概需要5分钟左右,部分截图如下:
2 配置完后,就可以直接编译和安装了
最后,直接使用执行这条命令
3 配置Nginx1.9.0,使之正常工作
成功安装Nginx1.9.0后,我们需要进行一些配置,包括开机启动、SSL/HTTPS服务等。其中,Nginx服务控制脚本
由于博客准备全站启用https服务,所以直接将前文《阿里云CentOS 6.5系统LNMP环境安装SSL证书》中产生的私钥typecodes.key和证书文件typecodes_last.crt打包的ssl.tar.gz上传到服务器使用。而Nginx配置文件nginx.conf见文章《2015博客升级记(六):Nginx配置HTTPS和SPDY实战》。
最后使用命令
4 错误分析
这里特意分析了一些Nginx安装过程中可能出现的错误情况,详见文章《Nginx编译安装时常见错误分析》。
我遇到的问题:在make的时候,遇到如下问题:
make[2]: 进入目录“/home/eastlhu/soft/nginx-1.9.15/pcre-8.38”
CDPATH="${ZSH_VERSION+.}:" && cd . && /bin/sh /home/eastlhu/soft/nginx-1.9.15/pcre-8.38/missing aclocal-1.15 -I m4
/home/eastlhu/soft/nginx-1.9.15/pcre-8.38/missing:行81: aclocal-1.15: 未找到命令
WARNING: 'aclocal-1.15' is missing on your system.
You should only need it if you modified 'acinclude.m4' or
'configure.ac' or m4 files included by 'configure.ac'.
The 'aclocal' program is part of the GNU Automake package:
<http://www.gnu.org/software/automake>
It also requires GNU Autoconf, GNU m4 and Perl in order to run:
<http://www.gnu.org/software/autoconf>
<http://www.gnu.org/software/m4/>
<http://www.perl.org/>
make[2]: *** [aclocal.m4] 错误 127
make[2]: 离开目录“/home/eastlhu/soft/nginx-1.9.15/pcre-8.38”
make[1]: *** [pcre-8.38/.libs/libpcre.a] 错误 2
make[1]: 离开目录“/home/eastlhu/soft/nginx-1.9.15”
make: *** [build] 错误 2
这时候进入pcre目录,执行 autoreconf -ivf
然后继续编译,报了一个:
groff -mandoc -f H -T ps zlib.3 | ps2pdf - zlib.3.pdf
/bin/sh: ps2pdf: 未找到命令
安装
安装ps2pdf yum -y install ghostscript
下面开始正文:
该文主要记录如何在CentOS 7.1中编译安装Nginx官方最新的1.9.0版本。由于像Nginx、Mysql和PHP7的的源码都是用C/C++写的,所以自己的CentOS 7.1服务器上必须要安装gcc和g++软件(CentOS 7系列会自带这两个编译软件)。
1 依赖库配置,编译和安装Nginx1.9.0
先创建一个名为nginx且
没有登录权限的用户和一个名为nginx的用户组,然后安装nginx所需的依赖库和依赖包,最后通过
.configure进行安装的详细配置。另外,补录一个pcre的tar包备份地址:https://o3cex9zsl.qnssl.com/libs/nginx/pcre-8.36.tar.gz,以及一个zlib的tar包备份地址:https://o3cex9zsl.qnssl.com/libs/nginx/zlib-1.2.8.tar.gz。
#######新建nginx用户和nginx组 [root@typecodes ~]# groupadd -r nginx && useradd -r -g nginx -s /bin/false -M nginx #######yum安装nginx必须的依赖库 [root@typecodes ~]# yum -y install openssl openssl-devel libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed #######官网下载Nginx1.9.0的tar包,然后解压到服务器上 [root@typecodes ~]# wget -c http://nginx.org/download/nginx-1.9.0.tar.gz [root@typecodes ~]# tar -zxf nginx-1.9.0.tar.gz && cd nginx-1.9.0 #######下载pcre的tar包并解压,以便支持Nginx的Rewrite功能 [root@typecodes nginx-1.9.0]# wget -c http://git.typecodes.com/libs/php/pcre-8.36.tar.gz && tar -zxf pcre-8.36.tar.gz #######下载zlib的tar包并解压,以便支持Nginx的Gzip压缩功能 [root@typecodes nginx-1.9.0]# wget -c http://git.typecodes.com/libs/nginx/zlib-1.2.8.tar.gz [root@typecodes nginx-1.9.0]# tar -zxf zlib-1.2.8.tar.gz #######新建Nginx1.9.0安装时所需要的目录 [root@typecodes nginx-1.9.0]# cd /var/tmp/ && mkdir -p /var/tmp/nginx/{client,proxy,fastcgi,uwsgi,scgi} [root@typecodes tmp]# mkdir -p /var/run/nginx && cd ~/nginx-1.9.0
准备工作做好后,就开始正式配置Nginx-1.9.0的安装明细了。注意,在使用下面这条
configure参数配置时,一定要先把反斜杠“\”后面添加的注释文字去掉!!!
[root@typecodes nginx-1.9.0]# ./configure \ --prefix=/usr/share/nginx \ [Nginx安装目录] --sbin-path=/usr/sbin/nginx \ [Nginx的sbin目录] --conf-path=/etc/nginx/nginx.conf \ [Nginx的配置文件] --error-log-path=/var/log/nginx/error.log \ [Nginx的错误日志] --http-log-path=/var/log/nginx/access.log \ [Nginx的访问日志] --pid-path=/var/run/nginx/nginx.pid \ [Nginx的进程ID] --lock-path=/var/lock/nginx.lock \ --user=nginx \ [Nginx所属用户] --group=nginx \ [Nginx所属用户组] --with-http_ssl_module \ [Nginx的ssl模块] --with-http_spdy_module \ [Nginx的Google spdy模块][1.9.5以上改为:--with-http_v2_module] --with-http_dav_module \ --with-http_flv_module \ --with-http_realip_module \ --with-http_addition_module \ --with-http_xslt_module \ --with-http_stub_status_module \ --with-http_sub_module \ --with-http_random_index_module \ --with-http_degradation_module \ --with-http_secure_link_module \ --with-http_gzip_static_module \ [Nginx的gzip压缩模块] --with-http_perl_module \ --with-pcre=pcre-8.36 \ [pcre的安装目录] --with-zlib=zlib-1.2.8 \ [pcre的安装目录] --with-debug \ [允许DEBUG] --with-file-aio \ --with-mail \ --with-mail_ssl_module \ --http-client-body-temp-path=/var/tmp/nginx/client_body \ --http-proxy-temp-path=/var/tmp/nginx/proxy \ --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi \ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \ --http-scgi-temp-path=/var/tmp/nginx/scgi \ --with-stream \ [Nginx1.9.0特有的stream模块] --with-ld-opt="-Wl,-E" [gcc的编译优化]
配置过程大概需要5分钟左右,部分截图如下:
2 配置完后,就可以直接编译和安装了
最后,直接使用执行这条命令
[root@typecodes nginx-1.9.0]# make && make install进行安装即可。其中,make命令和make install命令的执行结果附图如下:
3 配置Nginx1.9.0,使之正常工作
成功安装Nginx1.9.0后,我们需要进行一些配置,包括开机启动、SSL/HTTPS服务等。其中,Nginx服务控制脚本
nginx见文章《Nginx服务启动、停止和重启等操作的SHELL脚本》。
#######上传Nginx服务控制脚本nginx,并赋予执行权限,删除安装包,添加Nginx服务到开机启动 [root@typecodes ~]# mv ~/nginx /etc/init.d/nginx && chmod +x /etc/init.d/nginx [root@typecodes ~]# rm -rf nginx-1.9.0* [root@typecodes ~]# chkconfig --add nginx [root@typecodes ~]# chkconfig nginx on
由于博客准备全站启用https服务,所以直接将前文《阿里云CentOS 6.5系统LNMP环境安装SSL证书》中产生的私钥typecodes.key和证书文件typecodes_last.crt打包的ssl.tar.gz上传到服务器使用。而Nginx配置文件nginx.conf见文章《2015博客升级记(六):Nginx配置HTTPS和SPDY实战》。
#######上传ssl文件和Nginx配置文件nginx.conf [root@typecodes ~]# mkdir -p /etc/nginx/ssl && tar -zxf ~/ssl.tar.gz -C /etc/nginx/ssl [root@typecodes ~]# cd /etc/nginx/ && tar -zcf etc.nginx.tar.gz ./ [root@typecodes ~]# rm -rf ~/ssl.tar.gz [root@typecodes ~]# mv ~/nginx.conf /etc/nginx mv: overwrite ‘/etc/nginx/nginx.conf’? y #######测试配置是否正常 root@typecodes ~]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful #######新建Nginx进程日志nginx.pid目录,并启动服务 [root@typecodes ~]# mkdir -p /var/run/nginx/ [root@typecodes ~]# service nginx start Restarting nginx (via systemctl): [ OK ]
最后使用命令
[root@typecodes nginx]# nginx -V查看Nginx1.9.0的详细信息。
4 错误分析
这里特意分析了一些Nginx安装过程中可能出现的错误情况,详见文章《Nginx编译安装时常见错误分析》。
相关文章推荐
- Linux下nginx源码包安装
- Linux操作系统安装nginx
- 转:Nginx+ffmpeg的HLS开源服务器搭建配置及开发详解
- nginx-rtmp-module 指令详解
- nginx上传文件大小
- nginx配置优先级
- Redstone 云观象台 服务器部署 - Nginx配置文件
- nginx查看目标文件夹内容
- Nginx安装与配置文件解析
- 转: 基于nginx的hls直播系统
- linux安装nginx
- nginx rewrite proxy_pass location 的理解
- 2016 -Nginx的负载均衡 - 一致性哈希 (Consistent Hash)
- 转:nginx 从入门到精通的博文
- 使用Nginx负载均衡
- Nginx防攻击杀手锏
- Ubuntu FastDFSv5.05+Nginx1.9.15 环境搭建
- nginx的基本配置和虚拟主机的配置
- Ansible安装配置Nginx
- nginx禁止未绑定域名访问 并且强行断开连接