前言:
configure命令是编译安装Nginx的步骤,configure负责检测操作系统内核和已经安装的软件,参数的解析,中间目录的生成,以及根据各种参数生成一些C源文件、Makefile文件等;
make命令则根据configure命令生成的Makefile文件编译Nginx工程,并生成目标文件、最终的二进制文件;
make install命令根据configure执行时的参数将Nginx部署到指定的安装目录,包括相关目录的建立和二进制文件、配置文件的复制。
由此可见configure命令的重要性,使用help命令可以查看configure包含的参数:
./configure --help
参数较多,可分为四个类型:
1. 路径相关的参数: --- 编译到哪里去
2. 编译相关的参数: --- 用什么编译器
3. 依赖软件相关的参数: --- PCRE、OpenSSL、zlib在哪里
4. 模块相关的参数: --- 要什么模块,不要什么模块
5. 其他参数: --- 默认打印级别,支持IPv6
1. 路径相关的参数:
./configure --prefix = [PATH]
表示Nginx安装部署的目录,默认 /usr/local/nginx
举例:
./configure --prefix = /usr/local/my_nginx
2. 编译相关的参数:
./configure --with-cc = [PATH] #指定C编译器的路径
./configure --with-cpp = [PATH] #指定CPP编译器的路径
./configure --with-cc-opt = [OPTIONS] #加入编译选项
./configure --with-cpu-opt = [CPU] #指定CPU架构
3. 依赖软件相关的参数:
PCRE:
./configure --without-pcre #明确Nginx不需要使用PCRE正则表达式,也就是说,nginx.conf 配置文件中不使用正则表达式
./configure --with-pcre #强制使用PCRE正则表达式
./configure --with-pcre = [DIR] #指定PCRE库的位置,在编译Nginx时会进入该目录编译PCRE源码
./configure --with-pcre-opt = [OPTIONS] #编译PCRE源码时希望加入的Nginx选项
同理,OpenSSL:
./configure --with-openssl = [DIR]
./configure --with-openssl-opt = [OPTIONS]
zlib:
./configure --with-zlib = [DIR]
./configure --with-zlib-opt = [OPTIONS]
4. 模块相关的参数:
有些模块会默认编译进Nginx,有些默认不编译进去,可以通过configure命令选择:
(1)事件相关:
./configure --with-select_modllue
./configure --without-select_modlue
./configure --with-poll_module
./configure --without-poll_module
(2)HTTP模块,会默认编译进Nginx,所以下面提供的命令都是如何禁用HTTP功能的:
./configure --without-http_gzip_modlue
./configure --without-http_charset_module
(3)默认不编译进去的模块,如何加入:
./configure --with-http_ssl_module
(4)邮件代理服务器相关的:
./configure --with-mail
./configure --with-mail_ssl_module
./configure --without-mail_smtp_module
5. 其他参数:
./configure --with-debug #Nginx的打印级别直接配置成debug级
./configure --add-module = [PATH] #指定第三方模块的路径
./configure --without-http #禁用HTTP服务器
./configure --with-ipv6 #使Nginx支持IPv6
参考内容:
《深入理解Nginx – 模块开发与架构解析》