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/ ...
随机推荐
- C# Aes CryptoStream Specified padding mode is not valid for this algorithm的解決方法
//解密數據 using (var ss = File.OpenRead(@"d:\qq.d.flac")) { ...
- centos下安装pip2
# 背景 新机器,安装完python2后发现竟然不自带pip,按照我的理解现在新版本的python,不管是2还是3都会自带pip的.没办法,需要自己去安装pip的 # 步骤 1. 最开始查到的是通过y ...
- java随笔——HashMap与红黑树
前言: hashmap是一种很常用的数据结构,其使用方便快捷,接下来笔者将给大家深入解析这个数据结构,让大家能在用的时候知其然,也知其所以然. 一.Map 首先,从最基本的讲起,我们先来认识一下map ...
- TestNG参数化之@DataProvider传参
@parameters适合传递简单少量参数,复杂参数一般使用@DataProvider传递 @DataProvider语法: @DataProvider(name = "dataprovid ...
- Android 的一些中文文档
https://blog.csdn.net/qq_36467463/article/details/77990089 //安卓mediaformat api详解 https://www.cnbl ...
- 关于布尔值bool值
1.空或0布尔值为false,非0或非空为true 2.多个判断连在一起判断优先级:(括号)>not >and >or and: print(27 and 1>4) - ...
- 552. Student Attendance Record II
Given a positive integer n, return the number of all possible attendance records with length n, whic ...
- 【Oracle 12c】最新CUUG OCP-071考试题库(58题)
58.(16-1) choose the best answer: Examine the structure of the BOORSTRANSACTIONS table: Examine the ...
- 在myeclipse中有的项目上有个红色感叹号
之前做项目的时候遇到过这个问题,最后确定原因是项目引用了很多放在D盘或E盘上的jar包,但是我们不小心把这些jar包删除或移动路径了,因此myeclipse识别不了出现红色的感叹号,解决方式是在mye ...
- Using RDP to connect Windows remote desktop with Linux
安装rdesktop(一般情况下不需要这么做): sudo apt-get install rdesktop 执行连接: rdesktop xxx.xxx.xxx.xxx:3389 -u admini ...