nginx源码编译以及源码编译过程中遇到的问题
本文主要讲nginx安装以及安装过程中遇到的问题。
谈到nginx 必须聊聊它的起源和发展。
nginx是由俄罗斯工程师Igor Sysoev 用C语言开发的一个免费开源的Web服务器软件,于2004年发布,聚集轻量级、高并发、高性能、低消耗等一系列优点。目前Nginx是互联网上仅次于Apache的第二流行的Web服务器软件。
接下来我们开始安装nginx,我们下面是以centos7为基础环境进行搭建,我们的安装方法:一、yum安装 二、源码安装。
一、yum 安装
yum install nginx
如果你没有yum 源的话你需要配置下yum源:
vim /etc/yum.repos.d/nginx.repo
nginx.repo里填入以下内容:
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/x86_64/
gpgcheck=
enabled=
然后我们清除yum的缓存,进行安装
yum clean all
yum makecahe
yum install nginx
这样我们就成功安装好了nginx接下来讲讲源码安装,源码安装是可以个性化定制的。
二、源码安装
首先我们需要去下载源码包:
源码包下载地址:http://nginx.org/en/download.html,我们选择稳定版的包进行下载

然后我们进行解压和安装:
wget http://nginx.org/download/nginx-1.14.0.tar.gz
tar -xzvf nginx-1.14..tar.gz
cd nginx-1.14.
创建nginx用户和用户组
useradd -M -s /sbin/nologin nginx
在进行安装之前我们需要的一些通用配置选项:(官网源码编译配置文档路径:http://nginx.org/en/docs/configure.html )
--prefix=<path> nginx 的安装的根路径,所有其他的安装路径都要依赖于该选项
--sbin-path=<path> 指定nginx二进制文件的路径。如果没有指定,那么这个路径会依赖于--prefix选项
--conf-path=<path> 如果在命令行没有指定配置文件,那么将会通过这里指定的路径,nginx将会去那里查找它的配置文件,这里的路径要精确到文件.
--error-log-path=<path> 指定错误日志文件的路径,要精确到文件。
--pid-path=<path>指定pid文件的路径,通常在/var/run/下
--lock-path=<path>互斥锁文件的路径
--user=<user> worker进程运行的用户
--group=<group> worker进程运行的组
--with-http_ssl_module 启用ssl模块
以上是自定义安装的一些配置选项:
源码的安装一般由3个步骤组成:配置(configure)、编译(make)、安装(make install)。接下来我们开始进行编译安装,我会把安装过程中的遇到的问题贴出来。
mkdir /opt/nginx &&chown nginx:nginx /opt/nginx/
./configure --prefix=/opt/nginx/ --sbin-path=/usr/bin/ --conf-path=/etc/nginx/nginx.conf --user=nginx --group=nginx
#--prefix=/opt/nginx/ 指定nginx的安装目录是/opt/nginx
#--sbin-path=/usr/bin/ 指定nginx二进制文件的路径是/usr/bin
#--conf-path=/etc/nginx/nginx.conf 指定配置文件的路径
#--user=nginx 指定进程运行的用户
#--group=nginx 指定进程运行的用户
在编译的过程中我遇到了以下的错误,这里做个记录:
第一个错误 :./configure: error: C compiler cc is not found缺少gcc编译器。
解决方法:安装gcc编译器
yum -y install gcc-c++ autoconf automake
第二个错误:/configure: error: the HTTP rewrite module requires the PCRE library.确少PCRE库.
解决方法:安装PCRE
yum -y install pcre pcre-devel
第三个错误:./configure: error: the HTTP cache module requires md5 functions from OpenSSL library. You can either disable the module by using --without-http-cache option, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source with nginx by using --with-http_ssl_module --with-openssl=<path> options. 缺少ssl错误。
解决方法:安装openssl
yum -y install openssl openssl-devel
第四个错误:./configure: error: the HTTP gzip module requires the zlib library. 缺少zlib库
解决办法:安装zlib库
yum install -y zlib-devel
还有些错误是我没有遇到的,但是我在这边做下记录,以后可能会有帮助。
错误信息:./configure: error: the HTTP XSLT module requires the libxml2/libxslt 缺少libxml2
解决办法:yum -y install libxml2 libxml2-dev && yum -y install libxslt-devel
错误信息:./configure: error: the HTTP image filter module requires the GD library. You can either do not enable the module or install the libraries.
解决方法:http_image_filter_module是nginx提供的集成图片处理模块,需要gd-devel的支持 yum -y install gd-devel
错误信息:./configure: error: perl module ExtUtils::Embed is required 缺少ExtUtils
解决方法:yum -y install perl-devel perl-ExtUtils-Embed
错误信息:./configure: error: the GeoIP module requires the GeoIP library. You can either do not enable the module or install the library. 缺少GeoIP
解决方法:yum -y install GeoIP GeoIP-devel GeoIP-data
以上是配置过程中可能遇到的错误,接下来我们进行编译。
make -j 4
-j 参数的意义是并行编译,在多核的情况下可以提升编译速度
安装:
make install
然后我们需要更改一下目录的所有者和所属组,避免nginx运行时的权限问题
chown -R nginx:nginx /opt/nginx/
chown -R nginx:nginx /etc/nginx/
查看nginx的版本:
[root@test1 etc]# /usr/bin/nginx -v
nginx version: nginx/1.14.0
运行nginx
[root@test1 etc]# /usr/bin/nginx
[root@test1 etc]# ps -ef |grep nginx
root 8984 1 0 10:56 ? 00:00:00 nginx: master process /usr/bin/nginx
nginx 8985 8984 0 10:56 ? 00:00:00 nginx: worker process
root 8987 3060 0 10:56 pts/2 00:00:00 grep --color=auto nginx
然后我们就可以直接访问我们的ip的80端口(端口需要开放的)
如果开了防火墙可以关闭也可以开放80端口。
关闭防火墙:
systemctl stop firewalld
开放80端口:
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload
当我们看到这个界面就意味安装成功了:

三 、用 systemd 来管理 nginx
创建 service 文件,如果你的安装文件路径和下面的配置文件的路径不一致的时候,需要进行对应的替换。
cat <<EOF >> /usr/lib/systemd/system/nginx1.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target [Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=
KillMode=process
PrivateTmp=true [Install]
WantedBy=multi-user.target
EOF
通过 systemd 来管理 nginx
# 查看状态
systemctl status nginx
# 启动nginx
systemctl start nginx
# 暂停nginx
systemctl stop nginx
# 重启nginx
systemctl restart nginx # 设置开机自启 systemctl enable nginx
# 关闭开机自启
systemctl disable nginx
最后我们再讲讲几个nginx的命令:
指定配置文件启动:/usr/bin/nginx -c conf/nginx.conf
查看配置文件是否正确:/usr/bin/nginx -t
重新加载配置|重启|停止|退出 nginx : nginx -s reload|reopen|stop|quit
打开帮助信息: -?,-h
查看版本信息: -v
查看版本信息和配置信息: -V
以上就是安装nginx的一个笔记。
nginx源码编译以及源码编译过程中遇到的问题的更多相关文章
- zepto源码研究 - ajax.js(请求过程中的各个事件分析)
简要:ajax请求具有能够触发各类事件的功能,包括:触发全局事件,请求发送前事件,请求开始事件,请求结束事件等等,贯穿整个ajax请求过程,这是非常有用的,我们可以利用这些事件来做一些非常有意思的事情 ...
- Linux下编译安装源码包软件 configure ,make, make install, make test/check, make clean
http://www.360doc7.net/wxarticlenew/541275971.html 一.什么是源码包软件? 顾名思义,源码包就是源代码的可见的软件包,基于Linux和BSD系统的软件 ...
- Linux下编译安装源码包软件 configure ,make, make install, make test/check, make clean 假目标
http://www.360doc7.net/wxarticlenew/541275971.html 一.程序的组成部分 Linux下程序大都是由以下几部分组成: 二进制文件:也就是可以运行的程序文件 ...
- Lua源码编译之CL编译器编译
通过使用VC下的CL编译器,可方便地编译Lua源码,而无需构造工程并设置各种选项: 以下以源码Lua5.3.1版本为例,将通过CL编译选项直接编译源码,为方便编译将采用批处理脚本,脚本放置在Lua解压 ...
- 重新编译jdk源码,启用debug信息
我有一个不知道是好还是不好的习惯,搞不懂的一些玩意儿,喜欢调试然后单步执行看这玩意儿到底是怎么运行的. 今天看到正则表达式的时候,appendReplacement()这个方法怎么也看不明白它是怎么工 ...
- Linux编译安装源码包的流程
流程: 1. 下载并解压源码包2. 运行:configure3. 编译:make4. 安装:make install 编译时需要注意一个原则:不要在解压的包中直接执行./configure.m ...
- 编译Android源码
编译版本要求 基本安装环境 ubuntu 14.04 64 sudo apt-get install git-core gnupg flex bison gperf build-essential \ ...
- (转载)Linux如何编译安装源码包软件
一.什么是源码包软件: 顾名思义,源码包就是源代码的可见的软件包,基于Linux和BSD系统的软件最常见:在国内源可见的软件几乎绝迹:大多开源软件都是国外出品:在国内较为出名的开源软件有fcitx;l ...
- android源码环境下用mmm/mm编译模块,输出编译log到文件的方法
android源码环境下用mmm/mm编译模块,输出编译log到文件的方法 1,在android目录下直接用mmm命令编译, log信息保存在android目录下 mmm packages/apps/ ...
随机推荐
- Linux Context , Interrupts 和 Context Switching 说明
一. 进程Context 定义 当一个进程在执行时, CPU的所有寄存器中的值.进程的状态以及堆栈中的内容,比如各个变量和数据,包括所有的寄存器变量.进程打开的文件.内存信息等.这些信息被称为该进程的 ...
- JavaScript中的垃圾回收和内存泄漏
摘要: JS内存管理. 作者:浪里行舟 Fundebug经授权转载,版权归原作者所有. 前言 程序的运行需要内存.只要程序提出要求,操作系统或者运行时就必须供给内存.所谓的内存泄漏简单来说是不再用到的 ...
- memory leak-----tomcat日志warn
web应用借助于结构:spring mvc + quartz结构,部署到tomcat容器时,shutdown时的error信息: appears to have started a thread na ...
- airport 抓包
链接airport命令: ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources ...
- asp.net 添加错误日志
在开发程序中,错误日志很有必要.今天就把使用到的添加错误日志,记录下来,方便以后查看 利用的asp.net错误处理机制 Application_Error 贴出代码 protected void Ap ...
- ASP.NET2.0 Newtonsoft.Json 操作类分享
JSON 是现在比较流行的数据交互格式,NET3.0+有自带类处理JSON,2.0的话需要借助Newtonsoft.Json来完成,不然自己写的话,很麻烦. 网上搜索下载 Newtonsoft.Jso ...
- DevExpress GridControl使用教程:之 添加 checkbox 复选框
添加一列,FieldName为"FLAG",将ColumnEdit设置为复选框样式. gridview1 =>optionsbehavior => editabl ...
- deepin获取root权限
ctrk+alt+t 打开终端 输入 sudo passwd root mywork@mywork-PC:~$ sudo passwd root[sudo] mywork 的密码: [sudo] 输入 ...
- Python 错误和异常小结
1.Python异常类 Python是面向对象语言,所以程序抛出的异常也是类.常见的Python异常有以下几个,大家只要大致扫一眼,有个映像,等到编程的时候,相信大家肯定会不只一次跟他们照面(除非你不 ...
- python中的MRO和C3算法
一. 经典类和新式类 1.python多继承 在继承关系中,python子类自动用友父类中除了私有属性外的其他所有内容.python支持多继承.一个类可以拥有多个父类 2.python2和python ...