3.1 编译安装

1. 环境准备

为了编译Nginx源代码,我们需要标准的GCC编译器。除此之外,我们还需要Automake工具,以完成自动创建Makefile的工作。由于Nginx的一些模块需要依赖其他第三方库,通常有pcre库(支持rewrite模块)、zlib库(支持gzip模块)和openssl库(支持ssl模块)等。

yum -y install gcc gcc-c++ automake \
    pcre pcre-devel zlib zlib-devel open openssl-devel

2. 下载nginx

Nginx的官方下载网站为http://nginx.org/en/download.html。打开网站,可以看到,网页上提供了Nginx服务器三种版本的下载,分别是开发版本(Development version)稳定版本(Stable version)过期版本(Legacy versions)

wget http://nginx.org/download/nginx-1.24.0.tar.gz
tar -xzv -f nginx-1.24.0.tar.gz

3. 编译nginx

Nginx源代码的编译需要现使用configure脚本自动生成Makefile文件

cd nginx-1.24.0
./configure

得到了Nginx软件的Makefile文件后,我们就可以编译源代码了。使用make命令进行编译:

make

编译顺利完成以后,使用make的install命令安装Nginx软件:

make install

4. 检查

ls -l /usr/local/nginx
drwxr-xr-x. 2 root root 4096 10月 27 11:13 conf
drwxr-xr-x. 2 root root   40 10月 27 11:13 html
drwxr-xr-x. 2 root root    6 10月 27 11:13 logs
drwxr-xr-x. 2 root root   19 10月 27 11:13 sbin

5. 卸载

rm -rf /usr/local/nginx/
make clean

Last updated