编译nginx源码包

Posted zhangjian_999

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了编译nginx源码包相关的知识,希望对你有一定的参考价值。

源码包指的是开发编写好的程序源代码,但并没有将其编译为一个能正常使用的二进制工具,部分软件官网仅提供源码包,需要自行编译并安装,下面以nginx1.21.1版本为例;

1.下载源码包

在官网https://nginx.org/en/download.html找到源码包,复制链接地址下载:

[root@localhost data]# wget https://nginx.org/download/nginx-1.21.1.tar.gz

2.解压源码包,并进入目录

[root@localhost data]# tar xf nginx-1.21.1.tar.gz
[root@localhost data]# cd nginx-1.21.1

3.基础环境准备,先安装一些需要的环境

3.基础环境准备[root@localhost ~]# yum install -y gcc make

4.配置相关选项,生成makefile,中间会出现错误,需要安装相关软件包

[root@localhost nginx-1.21.1]# ./configure --prefix=/usr/local/nginx-1.21.1 --with-http_ssl_module --with-http_stub_status_module
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
[root@localhost nginx-1.21.1]# yum install -y pcre-devel zlib-devel
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.
[root@localhost nginx-1.21.1]# yum install openssl openssl-devel -y
[root@localhost nginx-1.21.1]# ./configure --prefix=/usr/local/nginx-1.21.1 --with-http_ssl_module --with-http_stub_status_module 

 5.编译并把相关文件释放到目录

[root@localhost nginx-1.21.1]# make	&& make install

6.创建软链接

[root@localhost nginx-1.21.1]# ln -s /usr/local/nginx-1.21.1/ /usr/local/nginx

7.启动nginx

[root@localhost nginx-1.21.1]# /usr/local/nginx/sbin/nginx

8.从浏览器访问虚拟机地址10.0.0.100显示 ,配置成功

 

以上是关于编译nginx源码包的主要内容,如果未能解决你的问题,请参考以下文章

源码编译三部曲(以nginx示例)

编译安装——什么是开放源代码编译器与可执行文件——编译安装nginx

源码包安装-例子

CentOS 7.2源码包编译安装nginx-1.10.2

Nginx1.8源码包编译安装

将源码编译打成rpm包----以nginx为例