下载
wget http://nginx.org/download/nginx-1.14.2.tar.gz
解压
tar -zxf nginx-1.14.2.tar.gz
目录介绍
[root@5e4a52ca308b nginx-1.14.2]# ll
total 752
-rw-r--r-- 1 1001 1001 288742 Dec 4 14:52 CHANGES //提供哪些特性和bugfix
-rw-r--r-- 1 1001 1001 440121 Dec 4 14:52 CHANGES.ru //俄罗斯版的CHANGES文件
-rw-r--r-- 1 1001 1001 1397 Dec 4 14:52 LICENSE
-rw-r--r-- 1 1001 1001 49 Dec 4 14:52 README
drwxr-xr-x 6 1001 1001 4096 Feb 23 07:35 auto //四个子目录如:cc(编译)、lib、os(判断操作系统)、types,其他文件辅助configure文件编译时判断nginx支持哪些模块
drwxr-xr-x 2 1001 1001 4096 Feb 23 07:35 conf //示例文件
-rwxr-xr-x 1 1001 1001 2502 Dec 4 14:52 configure //该脚本用了生成中间文件,编译前的必备动作
drwxr-xr-x 4 1001 1001 4096 Feb 23 07:35 contrib
drwxr-xr-x 2 1001 1001 4096 Feb 23 07:35 html //50x错误时重定向到50x.html和index.html欢迎页面
drwxr-xr-x 2 1001 1001 4096 Feb 23 07:35 man //帮助文件
drwxr-xr-x 9 1001 1001 4096 Feb 23 07:35 src //nginx源代码
configure
查看configure所支持参数:
./configure --help | more
注:此案例在docker拉取的coentos镜像容器中安装回报如下错误
./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.
解决方法
yum -y install pcre-*
configure
./configure --prefix=/home/nignx/nginx
/home/nignx/nginx编译目录
目录介绍
[root@5e4a52ca308b nginx-1.14.2]# ll
total 760
-rw-r--r-- 1 1001 1001 288742 Dec 4 14:52 CHANGES
-rw-r--r-- 1 1001 1001 440121 Dec 4 14:52 CHANGES.ru
-rw-r--r-- 1 1001 1001 1397 Dec 4 14:52 LICENSE
-rw-r--r-- 1 root root 380 Feb 23 08:42 Makefile
-rw-r--r-- 1 1001 1001 49 Dec 4 14:52 README
drwxr-xr-x 6 1001 1001 4096 Feb 23 07:35 auto
drwxr-xr-x 2 1001 1001 4096 Feb 23 07:56 conf
-rwxr-xr-x 1 1001 1001 2502 Dec 4 14:52 configure
drwxr-xr-x 4 1001 1001 4096 Feb 23 07:35 contrib
drwxr-xr-x 2 1001 1001 4096 Feb 23 07:35 html
drwxr-xr-x 2 1001 1001 4096 Feb 23 07:35 man
drwxr-xr-x 3 root root 4096 Feb 23 08:42 objs //目标文件如ngx_modules.c哪些模块会被编译进nginx
drwxr-xr-x 9 1001 1001 4096 Feb 23 07:35 src
编译安装
make && make install