3、 configure命令详解

发布时间 2023-12-26 17:09:44作者: ccblblog

1、configure命令工作

  • 检测操作系统内核和已安装的软件
  • 相关参数解析
  • 中间目录生成
  • 生成c源码文件
  • 生成Makefile文件

2、configure命令参数详解

运行 ./configure --help

  --help                             print this message

  --prefix=PATH                      set installation prefix
  --sbin-path=PATH                   set nginx binary pathname
  --conf-path=PATH                   set nginx.conf pathname
  --error-log-path=PATH              set error log pathname
  --pid-path=PATH                    set nginx.pid pathname
  --lock-path=PATH                   set nginx.lock pathname

  --user=USER                        set non-privileged user for
                                     worker processes
  --group=GROUP                      set non-privileged group for
                                     worker processes

  --builddir=DIR                     set build directory

  --with-rtsig_module                enable rtsig module
  --with-select_module               enable select module
  --without-select_module            disable select module
  --with-poll_module                 enable poll module
  --without-poll_module              disable poll module

  --with-file-aio                    enable file AIO support
  --with-ipv6                        enable IPv6 support

  --with-http_ssl_module             enable ngx_http_ssl_module
  --with-http_realip_module          enable ngx_http_realip_module
  --with-http_addition_module        enable ngx_http_addition_module
  --with-http_xslt_module            enable ngx_http_xslt_module
  --with-http_image_filter_module    enable ngx_http_image_filter_module
  --with-http_geoip_module           enable ngx_http_geoip_module
  --with-http_sub_module             enable ngx_http_sub_module
  --with-http_dav_module             enable ngx_http_dav_module
  --with-http_flv_module             enable ngx_http_flv_module
  --with-http_mp4_module             enable ngx_http_mp4_module
  --with-http_gzip_static_module     enable ngx_http_gzip_static_module
  --with-http_random_index_module    enable ngx_http_random_index_module
  --with-http_secure_link_module     enable ngx_http_secure_link_module
  --with-http_degradation_module     enable ngx_http_degradation_module
  --with-http_stub_status_module     enable ngx_http_stub_status_module

  --without-http_charset_module      disable ngx_http_charset_module
  --without-http_gzip_module         disable ngx_http_gzip_module
  --without-http_ssi_module          disable ngx_http_ssi_module
  --without-http_userid_module       disable ngx_http_userid_module
  --without-http_access_module       disable ngx_http_access_module
  --without-http_auth_basic_module   disable ngx_http_auth_basic_module
  --without-http_autoindex_module    disable ngx_http_autoindex_module
  --without-http_geo_module          disable ngx_http_geo_module
  --without-http_map_module          disable ngx_http_map_module
  --without-http_split_clients_module disable ngx_http_split_clients_module
  --without-http_referer_module      disable ngx_http_referer_module
  --without-http_rewrite_module      disable ngx_http_rewrite_module
  --without-http_proxy_module        disable ngx_http_proxy_module
  --without-http_fastcgi_module      disable ngx_http_fastcgi_module
  --without-http_uwsgi_module        disable ngx_http_uwsgi_module
  --without-http_scgi_module         disable ngx_http_scgi_module
  --without-http_memcached_module    disable ngx_http_memcached_module
  --without-http_limit_zone_module   disable ngx_http_limit_zone_module
  --without-http_limit_req_module    disable ngx_http_limit_req_module
  --without-http_empty_gif_module    disable ngx_http_empty_gif_module
  --without-http_browser_module      disable ngx_http_browser_module
  --without-http_upstream_ip_hash_module
                                     disable ngx_http_upstream_ip_hash_module

  --with-http_perl_module            enable ngx_http_perl_module
  --with-perl_modules_path=PATH      set Perl modules path
  --with-perl=PATH                   set perl binary pathname

  --http-log-path=PATH               set http access log pathname
  --http-client-body-temp-path=PATH  set path to store
                                     http client request body temporary files
  --http-proxy-temp-path=PATH        set path to store
                                     http proxy temporary files
  --http-fastcgi-temp-path=PATH      set path to store
                                     http fastcgi temporary files
  --http-uwsgi-temp-path=PATH        set path to store
                                     http uwsgi temporary files
  --http-scgi-temp-path=PATH         set path to store
                                     http scgi temporary files

  --without-http                     disable HTTP server
  --without-http-cache               disable HTTP cache

  --with-mail                        enable POP3/IMAP4/SMTP proxy module
  --with-mail_ssl_module             enable ngx_mail_ssl_module
  --without-mail_pop3_module         disable ngx_mail_pop3_module
  --without-mail_imap_module         disable ngx_mail_imap_module
  --without-mail_smtp_module         disable ngx_mail_smtp_module

  --with-google_perftools_module     enable ngx_google_perftools_module
  --with-cpp_test_module             enable ngx_cpp_test_module

  --add-module=PATH                  enable an external module

  --with-cc=PATH                     set C compiler pathname
  --with-cpp=PATH                    set C preprocessor pathname
  --with-cc-opt=OPTIONS              set additional C compiler options
  --with-ld-opt=OPTIONS              set additional linker options
  --with-cpu-opt=CPU                 build for the specified CPU, valid values:
                                     pentium, pentiumpro, pentium3, pentium4,
                                     athlon, opteron, sparc32, sparc64, ppc64

  --without-pcre                     disable PCRE library usage
  --with-pcre                        force PCRE library usage
  --with-pcre=DIR                    set path to PCRE library sources
  --with-pcre-opt=OPTIONS            set additional build options for PCRE

  --with-md5=DIR                     set path to md5 library sources
  --with-md5-opt=OPTIONS             set additional build options for md5
  --with-md5-asm                     use md5 assembler sources

  --with-sha1=DIR                    set path to sha1 library sources
  --with-sha1-opt=OPTIONS            set additional build options for sha1
  --with-sha1-asm                    use sha1 assembler sources

  --with-zlib=DIR                    set path to zlib library sources
  --with-zlib-opt=OPTIONS            set additional build options for zlib
  --with-zlib-asm=CPU                use zlib assembler sources optimized
                                     for the specified CPU, valid values:
                                     pentium, pentiumpro

  --with-libatomic                   force libatomic_ops library usage
  --with-libatomic=DIR               set path to libatomic_ops library sources

  --with-openssl=DIR                 set path to OpenSSL library sources
  --with-openssl-opt=OPTIONS         set additional build options for OpenSSL

  --with-debug                       enable debug logging

2.1 路径相关参数说明

参数名称 意义 默认值
--prefix=PATH Nginx安装部署后的根目录 默认为/usr/local/nginx目录。注意 :这个目标的设置会影响其他参数中的相对目录。例如,如果设置了--sbin-path=sbin/nginx,那么实际上可执行文件会被放到 /usr/local/nginx/sbin/nginx中
--sbin-path=PATH 可执行文件的放置路径 $prefix/sbin/nginx
--conf-path=PATH 配置文件的放置路径 $prefix/conf/nginx.conf
--error-log-path=PATH error日志文件的放置路径。error日志用于定位问题,可输出多种级别(包括debug调试级别)的日志。它的配置非常灵活,可以在nginx.conf里配置为不同请求的日志并输出到不同的 log 文件中。这里是默认的 Nginx 核心日志路径 $prefix/logs/error.log
--pid-path=PATH pid 文件的存放路径。这个文件里仅以ASCII码存放着Nginx master 的进程ID,有了这个进程ID,在使用命令行(例如nginx -s reload)通过读取 master 进程ID向master 进程发送信号时,才能对运行中的Nginx服务产生作用 $prefix/logs/nginx.pid
--lock-path=PATH lock 文件的放置路径 $prefix/logs/nginx.lock
--builddir=DIR configure执行时与编译期间产生的临时文件放置的目录,包括产生的 MakefileC 源文件、目标文件、可执行文件等 $nginx_source_path/objs
--with-perl_modules_path=PATH perl module放置的路径。只有使用了第三方的 perl module,才需要配置这个路径
--with-per=PATH perl binary放置的路径。如果配置的Nginx会执行 Perl脚本,那么就必须要设置此路径
--http-log-path=PATH access日志放置的位置。每一个HTTP请求在结束时都会记录的访问日志 $prefix/logs/access.log
--http-client-body-temp-path-PATH 处理HTTP请求时如果请求的包体需要暂时存放到临时磁盘文件中,则把这样的临时文件放置到该路径下 $prefix/client_body_temp
--http-proxy-temp-path=PATH Nginx 作为HTTP反向代理服务器时上游服务器产生的 HTTP 包体在需要临时存放到磁盘文件时,这样的临时文件将放到该路径下 $prefix/proxy_temp
--http-fastcgi-temp-path=PATH Fastcgi 所使用临时文件的放置目录 $prefix/fastcgi_temp
--http-uwsgi-temp-path-PATH uWSGI所使用临时文件的放置目录 $prefix/uwsgi_temp
--http-scgi-temp-path-PATH SCGI所使用临时文件的放置目录 $prefix/scgi_temp

2.2 编译相关参数说明

编译参数 意义
--with-cc=PATH C编译器的路径
--with-cpp=PATH C预编译器的路径
--with-cc-opt=OPTIONS 如果希望在Nginx编译期间指定加入一些编译选项,如指定宏或者使用-I加人某些需要包含的目录,这时可以使用该参数达成目的
--with-ld-opt=OPTIONS 最终的二进制可执行文件是由编译后生成的目标文件与一些第三方库链接生成的在执行链接操作时可能会需要指定链接参数,-with-ld-opt 就是用于加人链接时的参数。例如,如果我们希望将某个库链接到 Nginx 程序中,需要在这里加入--with-ldopt=-llibraryName -LlibraryPath,其中 libraryName 是目标库的名称,libraryPath则是目标库所在的路径
--with-cpu-opt=CPU 指定CPU处理器架构,只能从以下取值中选择:pentium、pentiumpro、pentium3pentium4、athlon、opteron、sparc32、sparc64、ppc64

2.3 依赖软件的相关参数

PCRE库的设置参数 意义
--without-pcre 如果确认Nginx不用解析正则表达式,也就是说,nginxconf配置文件中不会出现正则表达式,那么可以使用这个参数
--with-pcre 强制使用PCRE库
--with-pcre=DIR 指定PCRE库的源码位置,在编译Nginx时会进入该目录编译PCRE源码
--with-pcre-opt=OPTIONS 编译PCRE 源码时希望加人的编译选项
openSSL库的设置参数 意义
--with-openssl=DIR 指定OpenSSL库的源码位置,在编译Nginx 时会进入该目录编译 OpenSSL源码注意:如果 Web 服务器支持HTTPS,也就是SSL协议,Nginx 要求必须使用OpenSSL。可以访问 http://www.opensslorg/免费下载
--with-openssl-opt=OPTIONS 编译OpenSSL源码时希望加人的编译选项
atomic(原子)库的设置参数 意义
--with-libatomic 强制使用atomic库。atomic 库是CPU架构独立的一种原子操作的实现。它支持以下体系架构:x86(包括386和x86 64)、PPC64、Sparc64 (v9或更高版本)或者安装了GCC 4.1.0及更高本的架构。
--with-libatomic=DIR atomic库所在的位置
散列函数库的设置参数 意义
--with-MD5=DIR 指定MD5库的源码位置,在编译Nginx 时会进入该目录编译MD5 源码注意:Nginx源码中已经有了MD5算法的实现,如果没有特殊需求,那么完全可以使用 Nginx 自身实现的 MDS 算法
--with-MD5-opt=OPTIONS 编译MDS源码时希望加入的编译选项
---with-MD5-asm 使用MD5的汇编源码
--with-SHA1=DIR 指定SHA1库的源码位置,在编译 Nginx 时会进入该录编译SHAI 源码注意:OpenSSL中已经有了SHA1算法的实现。如果已经安装了 OpenSSL那么完全可以使用 OpenSSL 实现的 SHA1算法
--with-SHA1-opt=OPTIONS 编译SHA1源码时希望加人的编译选项
--with-SHA1-asm 使用SHA1的汇编源码
zlib库的设置参数 意义
--with-zlib=DIR 指定 zlib 库的源码位置,在编译 Nginx时会进入该目录编译 zlib 源码。如果使用了 gzip 压缩功能,就需要 zlib 库的支持
--with-zlib-opt=OPTIONS 编译zlib 源码时希望加入的编译选项
--with-zlib-asm=CPU 指定对特定的CPU使用zlib 库的汇编优化功能,目前仅支持两种架构:pentium pentiumpro

2.4 模块相关参数

事件模块编译参数 意义
--with-rtsig_module 使用rtsig module处理事件驱动默认情况下,Nginx是不安装rtsig module 的,即不会把rtsig module 编译进最终的
Nginx 二进制程序中
-with-select module 使用select module 处理事件驱动select是 Linux提供的一种多路复用机制,在epol1 调用没有诞生前,例如在 Linux2.4及其之前的内核中,select 用于支持服务器提供高并发连接默认情况下,Nginx是不安装 select module 的,但如果没有找到其他更好的事件模块,该模块将会被安装
--without-select module 不安装 select module
--with-poll_module 使用pollmodule处理事件驱动pol1的性能与 selet类似,在大量并发连接下性能都远不如epol1。默认情况下Nginx是不安装poll module的
--without-pollmodule 不安装pollmodule
--with-aio module 使用AIO方式处理事件驱动注意:这里的aio module 只能与 FreeBSD操作系统上的 kqueue 事件处理机制合作Linux上无法使用默认情况下是不安装aiomodule的
默认安装的HTTP模块 意义
--without-http_charset_module 不安装 http charset module。这个模块可以将服务器发出的HTTP响应重编码
--without-http_gzip_module 不安装 http gzip module。在服务器发出的HTTP 响应包中,这个模块可以按照配置文件指定的content-type对特定大小的HTTP响应包体执行 gzip 压缩
--without-httpssi_module 不安装 http ssi module。该模块可以在向用户返回的HTTP 响应包体中加入特定的内容,如HTML 文件中固定的页头和页尾
--without-http_userid_module 不安装http userid module。这个模块可以通过HTTP 请求头部信息里的一些字段认证用户信息,以确定请求是否合法
--without-http_access_module 不安装 http access module。这个模块可以根据IP 地址限制能够访问服务器的客户端
--without-http_auth_basic_module 不安装http auth basic module。这个模块可以提供最简单的用户名/密码认证
--without-http_autoindex_module 不安装 http autoindex module。该模块提供简单的目录浏览功能
--without-http_geo_module 不安装 http geo module。这个模块可以定义一些变量,这些变量的值将与客户端IP 地址关联,这样 Nginx 针对不同的地区的客户端(根据IP 地址判断)返回不一样的结果,例如不同地区显示不同语言的网页
--without-http_map_module 不安装http map module。这个模块可以建立一个key/value映射表不同的key 得到相应的 value,这样可以针对不同的URL 做特殊处理例如,返回302重定向响应时,可以期望URL 不同时返回的 Location字段也不一样
--without-http_split_clients_module 不安装http split client module。该模块会根据客户端的信息,例如IP 地址、header 头、cookie 等,来区分处理
--without-http_referer_module 不安装http referer module。该模块可以根据请求中的referer 字段来拒绝请求
--without-http_rewrite_module 不安装http rewrite module。该模块提供HTTP请求在Nginx服务内部的重定向功能,依赖PCRE库
--without-http_proxy_module 不安装http proxy module。该模块提供基本的HTTP反向代理功能
--without-http_fastcgi_module 不安装http fastcgimodule。该模块提供 FastCGI功能
--without-http_uwsgi_module 不安装 http uwsgi module。该模块提供uWSGI功能
--without-http_scgi_module 不安装 http scgi module。该模块提供SCGI功能
--without-http_memcached_module 不安装http memcached module。该模块可以使得 Nginx直接由上游的memcached 服务读取数据,并简单地适配成HTTP 响应返回给客户端
--without-http_limit_zone_module 不安装http limit zone module。该模块针对某个IP地限制并发连接数。例如,使 Nginx 对一个IP 地址仅允许一个连接
--without-http_limit_req_module 不安装http limit req module。该模块针对某个IP地址限制并发请
--without-http_empty_gif_module 不安装http empty gif module。该模块可以使得Nginx在收到无效请求时,立刻返回内存中的1X1像素的 GIF 图片。这种好处在于,对于明显的无效请求不会去试图浪费服务器资源
--without-http_browser_module 不安装http browser module。该模块会根据HTTP请求中的user-agent 字段(该字段通常由浏览器填写)来识别浏览器
--without-http_upstream_ip_hash_module 不安装http upstream ip hash module。该模块提供当Nginx 与后端server 建立连接时,会根据IP 做散列运算来决定与后端哪台 server 通信,这样可以实现负载均衡
可选的HTTP模块 意义
--with-http_ssl_module 安装http sslmodule。该模块使Nginx 支持SSL协议,提供HTTPS 服务注意:该模块的安装依赖于 OpenSSL开源软件,即首先应确保已经在之前的参数中配置了OpenSSL
--with-http_realip_module 安装 http realip module。该模块可以从客户端请求里的 header 信息(如X-Real-IP 或者X-Forwarded-For)中获取真正的客户端IP地址
--with-http_addition_module 安装http addtion module。该模块可以在返回客户端的HTTP包体头部或者尾部增加内容
--with-http_xslt_module 安装http xslt module。这个模块可以使XML格式的数据在发给客户端前加入XSL 渲染, 注意:这个模块依赖于libxm12 和libxsit 库,安装它前首先确保上述两个软件已经安装
--with-http_image_filter_module 安装http image_filter_module。这个模块将符合配置的图片实时压缩为指定大小(width*height)的缩略图再发送给用户,目前支持JPEG、PNGGIF 格式。注意:这个模块依赖于开源的 lbgd 库,在安装前确保操作系统已经安装 libgd
--with-http_geoip_module 安装http geoip module。该模块可以依据MaxMind GeoIP的IP地址数据库对客户端的 IP 地址得到实际的地理位置信息注意:该库依赖于MaxMind GeoIP的库文件,可访问 http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
--with-http_sub_module 获取安装http sub module。该模块可以在Nginx返回客户端的HTTP响应包中将指定的字符串替换为自己需要的字符串例如,在HTML的返回中,将</head> 替换为</head><script language "javascriptsrc="$script">
--with-http_dav_module 安装 http dav module。这个模块可以让Nginx 支持 Webdav 标准,如支持Webdav 协议中的PUT、DELETE、COPY、MOVE、MKCOL 等请求
--with-http_flv_module 安装http flv module。这个模块可以在向客户端返回响应时,对FLV格式的视频文件在 header 头做一些处理,使得客户端可以观看、拖动 FLV 视频
--with-http_mp4_module 安装 http mp4 module。该模块使客户端可以观看、拖动MP4 视频
--with-http_gzip_static_module 安装http gzip static module。如果采用gzip 模块把一些文档进行gzip 格式压缩后再返回给客户端,那么对同一个文件每次都会重新压缩,这是比较消耗服务器CPU资源的。gzip static 模块可以在做gzip 压缩前,先查看相同位置是否有已经做过 gzip 压缩的gz 文件,如果有,就直接返回。这样就可以预先在服务器上做好文档的压缩,给 CPU 减负
--with-http_random_index_module 安装http random index module。该模块在客户端访问某个目录时,随机返回该目录下的任意文件
--with-http_secure_link_module 安装http secure link module。该模块提供一种验证请求是否有效的机制。例如,它会验证URL中需要加入的 token 参数是否属于特定客户端发来的以及检查时间戳是否过期
--with-http_degradation module 安装http degradation module。该模块针对一些特殊的系统调用(如sbrk)做一些优化,如直接返回 HTTP 响应码为204 或者444。目前不支持 Linux系统
--with-http_stub_status_module 安装http stub status module。该模块可以让运行中的Nginx提供性能统计页面,获取相关的并发连接、请求的信息
--with-google_perftools module 安装google perftools module。该模块提供Google 的性能测试工具
可选email模块 意义
--with-mail 安装邮件服务器反向代理模块,使Nginx 可以反向代理IMAP、POP3、SMTP等协议。该模块默认不安装
--with-mail_ssl_module 安装mail ssl module。该模块可以使IMAP、POP3、SMTP 等协议基于SSL/TLS协议之上使用。该模块默认不安装并依赖于OpenSSL库
--without-mail_pop3_module 不安装mail pop3 module。在使用--with-mail参数后,pop3 module是默认安装的,以使 Nginx 支持 POP3 协议
--without-mail_imap_module 不安装mail imap module。在使用--with-mail 参数后,imap module 是默认安装的,以使Nginx支持 IMAP
--without-mail_smtp_module 不安装mailsmtp module。在使用--with-mail参数后,smtp module 是默认安装的,以使Nginx支持SMTP

2.5 其他参数

其他参数 意义
--with-debug 将Nginx需要打印 debug调试级别日志的代码编译进Nginx。这样可以在Nginx 运行时通过修改配置文件来使其打印调试日志,这对于研究、定位 Nginx问题非常有帮助
--add-module=PATH 当在Nginx里加入第三方模块时,通过这个参数指定第三方模块的路径。这个参数将在下文如何开发 HTTP块时使用到
--without-http 禁用HTTP服务器
--without-http-cache 禁用HTTP服务器里的缓存Cache 特性
--with-file-aio 启用文件的异步 I/0 功能来处理磁盘文件,这需要 Linux 内核支持原生的异步I/0
--with-ipv6 使Nginx支持IPv6
--user-USER 指定Nginx worker进程运行时所属的用户注意:不要将启动 worker进程的用户设为root,在 worker 进程出问题时master进程要具备停止/启动 worker 进程的能力
--group=GROUP 指定Nginx worker进程运行时所属的组