Nginx 系列 - 编译出适合自己的 Nginx
一、安装说明
1. 下载解压
版本选择,此处选择最新的 Stable 版本 1.16.0:
$ wget http://nginx.org/download/nginx-1.16.0.tar.gz
$ tar -xzf nginx-1.16.0.tar.gz
版本说明:
- Mainline version:主干版本,包含最新特性,但可能不稳定
- Stable version:稳定版本,建议生产使用该版本
2. 源码目录
$ cd nginx-1.16.0
$ tree -L 1 nginx-1.16.0
|-- CHANGES
|-- CHANGES.ru
|-- LICENSE
|-- README
|-- auto
|-- conf
|-- configure
|-- contrib
|-- html
|-- man
`-- src
3. 安装配置
这里只配置了安装路径,其它选项根据自己需要选择,配置完成后会提示相关文件路径:
$ ./configure --prefix=/usr/local/nginx
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
并生成中间文件在 objs 目录下:
$ tree -L 1 objs
|-- Makefile
|-- autoconf.err
|-- ngx_auto_config.h
|-- ngx_auto_headers.h
|-- ngx_modules.c
`-- src
查看更多配置:
$ ./configure --help | more
4. 编译
编译后会生成中间文件和可执行的 nginx 二进制文件:
$ make
$ tree -L 1 objs
|-- Makefile
|-- autoconf.err
|-- nginx
|-- nginx.8
|-- ngx_auto_config.h
|-- ngx_auto_headers.h
|-- ngx_modules.c
|-- ngx_modules.o
`-- src
5. 安装
初次安装则直接执行 make install,如果是升级则是将上面的 nginx 二进制文件复制到安装目录:
$ make install
6. 启动
$ /usr/local/nginx/sbin/nginx
7. 访问
打开浏览器访问http://127.0.0.1/
,如果出现以下页面则安装成功:
二、其它说明
1. 语法高亮
让 Nginx 配置文件在 Vim 编辑器中高亮显示,只需将安装包中的配置文件复制到宿主目录的配置目录即可:
$ cd nginx-1.16.0
$ cp -r ./contrib/vim/* ~/.vim/
2. 系统包
由于本人使用的是 centos 的 docker 镜像进行测试,需安装以下系统包:
$ yum -y install wget tree
$ yum -y install gcc gcc-c++ autoconf automake
$ yum -y install zlib zlib-devel openssl openssl-devel pcre-devel
3. 相关资料
本文首发于马燕龙个人博客,欢迎分享,转载请标明出处。
马燕龙个人博客:https://www.mayanlong.com
马燕龙个人微博:http://weibo.com/imayanlong
马燕龙Github主页:https://github.com/yanlongma
不错,不错,对我有帮助! 我要打赏他!GO ->