nginx实用指南一: 从源码安装nginx

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Lunar_lty/article/details/79942243

一. 下载
首先,从这里点击下载nginx-1.12.2版本,在安装之前,可先运行df -hl命令看看磁盘控件还剩多少,如下:

Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 2.4G 36G 7% /
tmpfs 499M 0 499M 0% /dev/shm

可见,剩余的磁盘空间完全可以安装nginx。

二. 解压
使用命令tar -xf nginx-1.12.2.tar.gz解压即可

三. 配置
进入解压后的目录,可以看到./configure配置程序,运行此配置程序的作用是为了根据具体的配置,来生成不同的编译选项或者makefile,供make工具使用。下面介绍一下其配置选项:

选项 含义 缺省值
–prefix=path 定义一个用于保存server文件的路径,这个路径也被用作nginx.conf配置文件的相对路径 /usr/local/nginx
–sbin-path=path 设置nginx可执行文件名称,改名称仅在安装时生效 prefix/sbin/nginx
–conf-path=path 设置nginx.conf的路径;如果需要的话,nginx可以在启动时通过-c选项指定 prefix/conf/nginx.conf
–pid-path=path 设置nginx.pid文件所在路径. 安装完成之后,该路径可以通过在nginx.conf配置文件中使用pid指令进行设定 prefix/logs/nginx.pid
–error-log-path=path 设置nginx运行异常,警告等错误日志所在路径,该路径可通过在nginx.conf中使用error_log指令进行设定 prefix/logs/error.log
–http-log-path=path 设置http请求日志路径,该路径可通过在nginx.conf中使用access_log指令进行设定 prefix/logs/access.log.
–build=name 设定一个可选的构建名 nginx
–user=name 设置一个非特权的用户,该用户的证书将为nginx workder进程所使用;可在nginx.conf中使用user指令进行设定 nobody
–group=name 设定一个组名,该组的证书将为nginx worker进程所使用;可在nginx.conf中使用user指令进行设定 缺省为user所在的组
–with-select_module –without-select_module enables/disables 服务端使用select模型进行通讯 如果平台不支持高性能的网络模型例如kqueue, epoll, or /dev/poll,将默认开启select
–with-poll_module –without-poll_module enables/disables 服务端使用poll()IO模型. This module is built automatically if the platform does not appear to support more appropriate methods such as kqueue, epoll, or /dev/poll.
–without-http_gzip_module 禁用http server压缩response功能. 如果不禁用则需要zlib库 none
–with-zlib=path 设定zlib库的源码路径. The library distribution (version 1.1.3 — 1.2.11) 需在zlib站点上下载并解压好,其余的由nginx make来完成. zlib库为ngx_http_gzip_module模块所引用 none
–without-http_rewrite_module 禁用 HTTP server重定向请求 或 修改请求URI 的功能. 如果不禁用则需要引用PCRE 库 none
–with-pcre=path 设定PCRE库路径. The library distribution (version 4.4 — 8.41) 需要下载并解压好,在location指令中使用正则表达式时,需要使用这个库,另外,ngx_http_rewrite_module模块也使用到了这个库 none
–without-http_proxy_module 禁用HTTP server代理模块 none
–with-http_ssl_module 开启HTTPS协议,需要OpenSSL库 缺省未设置
–with-pcre-jit 使用“just-in-time compilation”编译pcre库, support (1.1.12, the pcre_jit directive). none
–with-cc-opt=parameters 设定将被添加到CFLAGS变量中的额外参数,当在FreeBSD系统中使用PCRE library库时,–with-cc-opt=”-I /usr/local/include”需要被指定。如果select()模型的最大文件数需要指定,可以这样操作:–with-cc-opt=”-D FD_SETSIZE=2048” none
–with-ld-opt=parameters 设定额外的链接参数, 当在FreeBSD系统下使用PCRE库时,需设定–with-ld-opt=”-L /usr/local/lib” none

笔者所使用的pcre库版本为8.41,点击此处可下载pcre库,zlib库为zlib-1.2.11,点击此处可下载zlib
在我们了解上述配置含义之后,可使用如下配置:
./configure
–sbin-path=/usr/local/nginx/nginx
–conf-path=/usr/local/nginx/nginx.conf
–pid-path=/usr/local/nginx/nginx.pid
–with-http_ssl_module
–with-pcre=../pcre-8.41
–with-zlib=../zlib-1.2.11

四. 编译
配置完毕之后,直接make,然后等待编译完成。

五. 引用
[1]. Building nginx from Sources

猜你喜欢

转载自blog.csdn.net/Lunar_lty/article/details/79942243