从源代码构建 Nginx

使用configure命令配置该版本。它定义了系统的各个方面,包括允许 nginx 用于连接处理的方法。最后,它创建一个Makefile

configure命令支持以下参数:

  • --help

    • 打印帮助信息。
  • --prefix=path

    • 定义将保留服务器文件的目录。此相同目录还将用于configure设置的所有相对路径(库源路径除外)和nginx.conf配置文件中的路径。默认情况下,它设置为/usr/local/nginx目录。
  • --sbin-path=path

    • 设置 nginx 可执行文件的名称。此名称仅在安装期间使用。默认情况下,文件名为prefix/sbin/nginx
  • --modules-path=path

    • 定义将在其中安装 nginx 动态模块的目录。默认情况下,使用prefix/modules目录。
  • --conf-path=path

    • 设置nginx.conf配置文件的名称。如果需要,可以通过在命令行参数-c file中指定 nginx 来始终使用其他配置文件来启动它。默认情况下,文件名为prefix/conf/nginx.conf
  • --error-log-path=path

    • 设置主要错误,警告和诊断文件的名称。安装后,始终可以使用error_log指令在nginx.conf配置文件中更改文件名。默认情况下,文件名为prefix/logs/error.log
  • --pid-path=path

    • 设置nginx.pid文件的名称,该文件将存储主进程的进程 ID。安装后,始终可以使用pid指令在nginx.conf配置文件中更改文件名。默认情况下,文件名为prefix/logs/nginx.pid
  • --lock-path=path

    • 为锁定文件的名称设置前缀。安装后,可以始终使用lock_file指令在nginx.conf配置文件中更改该值。默认情况下,值为prefix/logs/nginx.lock
  • --user=name

    • 设置非特权用户的名称,其凭据将由工作进程使用。安装后,可以始终使用user指令在nginx.conf配置文件中更改名称。默认用户名是 nobody。
  • --group=name

    • 设置其凭据将由工作进程使用的组的名称。安装后,可以始终使用user指令在nginx.conf配置文件中更改名称。默认情况下,组名设置为非特权用户的名称。

--build=name

  • 设置一个可选的 nginx 构建名称。

  • --builddir=path

    • 设置构建目录。
  • --with-select_module
    --without-select_module

    • 启用或禁用构建允许服务器使用select()方法工作的模块。如果平台似乎不支持更合适的方法(例如 kqueue,epoll 或/ dev/poll),则会自动构建此模块。
  • --with-poll_module
    --without-poll_module

    • 启用或禁用构建允许服务器使用poll()方法工作的模块。如果平台似乎不支持更合适的方法(例如 kqueue,epoll 或/ dev/poll),则会自动构建此模块。
  • --with-threads

  • --with-file-aio

  • --with-http_ssl_module

    • 启用构建将HTTPS 协议支持添加到 HTTP 服务器的模块的功能。默认情况下未构建此模块。需要 OpenSSL 库来构建和运行此模块。
  • --with-http_v2_module

    • 启用构建支持HTTP/2的模块的功能。默认情况下未构建此模块。
  • --with-http_realip_module

    • 支持构建ngx_http_realip_module模块,该模块将客户地址更改为在指定的 Headers 字段中发送的地址。默认情况下未构建此模块。
  • --with-http_addition_module

    • 使您能够构建ngx_http_addition_module模块,该模块在响应前后添加文本。默认情况下未构建此模块。
  • --with-http_xslt_module
    --with-http_xslt_module=dynamic

    • 支持构建ngx_http_xslt_module模块,该模块使用一个或多个 XSLT 样式表转换 XML 响应。默认情况下未构建此模块。 libxml2libxslt库是构建和运行此模块所必需的。
  • --with-http_image_filter_module
    --with-http_image_filter_module=dynamic

    • 支持构建ngx_http_image_filter_module模块,该模块可以转换 JPEG,GIF,PNG 和 WebP 格式的图像。默认情况下未构建此模块。
  • --with-http_geoip_module
    --with-http_geoip_module=dynamic

    • 支持构建ngx_http_geoip_module模块,该模块根据客户端 IP 地址和预编译的MaxMind数据库创建变量。默认情况下未构建此模块。
  • --with-http_sub_module

    • 允许构建ngx_http_sub_module模块,该模块通过将一个指定的字符串替换为另一字符串来修改响应。默认情况下未构建此模块。
  • --with-http_dav_module

    • 支持构建ngx_http_dav_module模块,该模块通过 WebDAV 协议提供文件管理自动化。默认情况下未构建此模块。
  • --with-http_flv_module

    • 支持构建ngx_http_flv_module模块,该模块为 Flash 视频(FLV)文件提供伪流服务器端支持。默认情况下未构建此模块。
  • --with-http_mp4_module

    • 支持构建ngx_http_mp4_module模块,该模块为 MP4 文件提供伪流服务器端支持。默认情况下未构建此模块。
  • --with-http_gunzip_module

    • 可以为不支持“ gzip”编码方法的客户端构建ngx_http_gunzip_module模块,以“ Content-Encoding: gzip”解压缩响应。默认情况下未构建此模块。
  • --with-http_gzip_static_module

    • 启用构建ngx_http_gzip_static_module模块的功能,该模块可以发送文件 extensions 为“ .gz”的预 zipfile,而不是常规文件。默认情况下未构建此模块。
  • --with-http_auth_request_module

    • 允许构建ngx_http_auth_request_module模块,该模块根据子请求的结果实现客户端授权。默认情况下未构建此模块。
  • --with-http_random_index_module

    • 支持构建ngx_http_random_index_module模块,该模块处理以斜杠字符(/)结尾的请求,并从目录中选择一个随机文件作为索引文件。默认情况下未构建此模块。
  • --with-http_secure_link_module

  • --with-http_degradation_module

    • 启用构建ngx_http_degradation_module模块。默认情况下未构建此模块。
  • --with-http_slice_module

    • 支持构建ngx_http_slice_module模块,该模块将请求分为多个子请求,每个子请求都返回一定范围的响应。该模块提供了更有效的大响应缓存。默认情况下未构建此模块。
  • --with-http_stub_status_module

  • --without-http_charset_module

    • 禁用构建ngx_http_charset_module模块,该模块将指定的字符集添加到“ Content-Type”响应头字段中,并且可以将数据从一个字符集转换为另一个字符集。
  • --without-http_gzip_module

    • 禁用构建 HTTP 服务器compresses responses的模块。 zlib 库是构建和运行此模块所必需的。
  • --without-http_ssi_module

  • --without-http_userid_module

  • --without-http_access_module

  • --without-http_auth_basic_module

    • 禁用构建ngx_http_auth_basic_module模块,该模块允许通过使用“ HTTP 基本认证”协议验证用户名和密码来限制对资源的访问。
  • --without-http_mirror_module

  • --without-http_autoindex_module

  • --without-http_geo_module

    • 禁用构建ngx_http_geo_module模块,该模块创建的变量的值取决于客户端 IP 地址。
  • --without-http_map_module

    • 禁用构建ngx_http_map_module模块,该模块创建的变量的值取决于其他变量的值。
  • --without-http_split_clients_module

  • --without-http_referer_module

    • 禁用构建ngx_http_referer_module模块,该模块可以阻止“ Referer”标题字段中具有无效值的请求访问站点。
  • --without-http_rewrite_module

  • --without-http_proxy_module

  • --without-http_fastcgi_module

  • --without-http_uwsgi_module

  • --without-http_scgi_module

  • --without-http_grpc_module

  • --without-http_memcached_module

  • --without-http_limit_conn_module

    • 禁用构建ngx_http_limit_conn_module模块的功能,该模块限制每个键的连接数,例如,单个 IP 地址的连接数。
  • --without-http_limit_req_module

    • 禁用构建限制每个密钥的请求处理速率的ngx_http_limit_req_module模块,例如,来自单个 IP 地址的请求的处理速率。
  • --without-http_empty_gif_module

  • --without-http_browser_module

    • 禁用构建ngx_http_browser_module模块,该模块创建的变量的值取决于“ User-Agent”请求 Headers 字段的值。
  • --without-http_upstream_hash_module

    • 禁用构建实现hash负载平衡方法的模块。
  • --without-http_upstream_ip_hash_module

    • 禁用构建实现ip_hash负载平衡方法的模块。
  • --without-http_upstream_least_conn_module

    • 禁用构建实现least_conn负载平衡方法的模块。
  • --without-http_upstream_keepalive_module

    • 禁用构建为上游服务器提供连接缓存的模块。
  • --without-http_upstream_zone_module

    • 禁用构建一个模块,该模块可以将上游组的运行时状态存储在共享内存zone中。
  • --with-http_perl_module
    --with-http_perl_module=dynamic

  • --with-perl_modules_path=path

    • 定义一个目录,该目录将保留 Perl 模块。
  • --with-perl=path

    • 设置 Perl 二进制文件的名称。
  • --http-log-path=path

    • 设置 HTTP 服务器的主请求日志文件的名称。安装后,始终可以使用access_log指令在nginx.conf配置文件中更改文件名。默认情况下,文件名为prefix/logs/access.log
  • --http-client-body-temp-path=path

    • 定义用于存储包含客户端请求正文的临时文件的目录。安装后,可以始终使用client_body_temp_path指令在nginx.conf配置文件中更改目录。默认情况下,目录名为prefix/client_body_temp
  • --http-proxy-temp-path=path

    • 定义一个目录,用于存储带有从代理服务器接收到的数据的临时文件。安装后,可以始终使用proxy_temp_path指令在nginx.conf配置文件中更改目录。默认情况下,目录名为prefix/proxy_temp
  • --http-fastcgi-temp-path=path

    • 定义一个目录,用于存储包含从 FastCGI 服务器接收到的数据的临时文件。安装后,可以始终使用fastcgi_temp_path指令在nginx.conf配置文件中更改目录。默认情况下,目录名为prefix/fastcgi_temp
  • --http-uwsgi-temp-path=path

    • 定义一个目录,用于存储包含从 uwsgi 服务器接收到的数据的临时文件。安装后,可以始终使用uwsgi_temp_path指令在nginx.conf配置文件中更改目录。默认情况下,目录名为prefix/uwsgi_temp
  • --http-scgi-temp-path=path

    • 定义一个目录,用于存储包含从 SCGI 服务器接收到的数据的临时文件。安装后,可以始终使用scgi_temp_path指令在nginx.conf配置文件中更改目录。默认情况下,目录名为prefix/scgi_temp
  • --without-http

    • 禁用HTTP服务器。
  • --without-http-cache

    • 禁用 HTTP 缓存。
  • --with-mail
    --with-mail=dynamic

  • --with-mail_ssl_module

    • 启用构建将SSL/TLS 协议支持添加到邮件代理服务器的模块的功能。默认情况下未构建此模块。需要 OpenSSL 库来构建和运行此模块。
  • --without-mail_pop3_module

    • 禁用邮件代理服务器中的POP3协议。
  • --without-mail_imap_module

    • 禁用邮件代理服务器中的IMAP协议。
  • --without-mail_smtp_module

    • 禁用邮件代理服务器中的SMTP协议。
  • --with-stream
    --with-stream=dynamic

    • 可以为通用的 TCP/UDP 代理和负载平衡构建stream module。默认情况下未构建此模块。
  • --with-stream_ssl_module

    • 启用构建将SSL/TLS 协议支持添加到流模块的模块的功能。默认情况下未构建此模块。需要 OpenSSL 库来构建和运行此模块。
  • --with-stream_realip_module

    • 支持构建ngx_stream_realip_module模块,该模块将客户地址更改为 PROXY 协议 Headers 中发送的地址。默认情况下未构建此模块。
  • --with-stream_geoip_module
    --with-stream_geoip_module=dynamic

    • 支持构建ngx_stream_geoip_module模块,该模块根据客户端 IP 地址和预编译的MaxMind数据库创建变量。默认情况下未构建此模块。
  • --with-stream_ssl_preread_module

  • --without-stream_limit_conn_module

  • --without-stream_access_module

  • --without-stream_geo_module

    • 禁用构建ngx_stream_geo_module模块,该模块创建的变量的值取决于客户端 IP 地址。
  • --without-stream_map_module

  • --without-stream_split_clients_module

  • --without-stream_return_module

  • --without-stream_upstream_hash_module

    • 禁用构建实现hash负载平衡方法的模块。
  • --without-stream_upstream_least_conn_module

    • 禁用构建实现least_conn负载平衡方法的模块。
  • --without-stream_upstream_zone_module

    • 禁用构建一个模块,该模块可以将上游组的运行时状态存储在共享内存zone中。
  • --with-google_perftools_module

  • --with-cpp_test_module

    • 启用构建ngx_cpp_test_module模块。
  • --add-module=path

    • 启用外部模块。
  • --add-dynamic-module=path

    • 启用外部动态模块。
  • --with-compat

    • 启用动态模块兼容性。
  • --with-cc=path

    • 设置 C 编译器的名称。
  • --with-cpp=path

    • 设置 C 预处理器的名称。
  • --with-cc-opt=parameters

    • 设置将添加到 CFLAGS 变量的其他参数。在 FreeBSD 下使用系统 PCRE 库时,应指定--with-cc-opt="-I /usr/local/include"。如果需要增加select()支持的文件数量,也可以在此处指定,例如:--with-cc-opt="-D FD_SETSIZE=2048"
  • --with-ld-opt=parameters

    • 设置在链接期间将使用的其他参数。在 FreeBSD 下使用系统 PCRE 库时,应指定--with-ld-opt="-L /usr/local/lib"
  • --with-cpu-opt=cpu

    • 启用每个指定 CPU 的构建:pentiumpentiumpropentium3pentium4athlonopteronsparc32sparc64ppc64
  • --without-pcre

    • 禁用 PCRE 库的使用。
  • --with-pcre

    • 强制使用 PCRE 库。
  • --with-pcre=path

    • 设置 PCRE 库源的路径。需要从PCRE站点下载并分发库分发(版本 4.4 — 8.43)。其余的由 nginx 的./configuremake完成。 location指令中的正则表达式支持和ngx_http_rewrite_module模块都需要该库。
  • --with-pcre-opt=parameters

    • 为 PCRE 设置其他构建选项。
  • --with-pcre-jit

    • 使用“及时编译”支持(1.1.12,pcre_jit指令)构建 PCRE 库。
  • --with-zlib=path

    • 设置 zlib 库源的路径。需要从zlib站点下载并分发库发行版(版本 1.1.3-1.2.11)。其余的由 nginx 的./configuremake完成。 ngx_http_gzip_module模块需要该库。
  • --with-zlib-opt=parameters

    • 为 zlib 设置其他构建选项。
  • --with-zlib-asm=cpu

    • 支持使用针对以下指定 CPU 之一优化的 zlib 汇编器源:pentiumpentiumpro
  • --with-libatomic

    • 强制使用 libatomic_ops 库。
  • --with-libatomic=path

    • 设置 libatomic_ops 库源的路径。
  • --with-openssl=path

    • 设置 OpenSSL 库源的路径。
  • --with-openssl-opt=parameters

    • 为 OpenSSL 设置其他构建选项。
  • --with-debug

参数用法示例(所有这些都需要在一行中键入):

./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.44
    --with-zlib=../zlib-1.2.11

配置完成后,使用make编译并安装 nginx。