Nginx源代码编绎参数详解

2018-11-13 21:00:00
赵勤松
原创
2122
摘要:Nginx做为流行的Web Server,广泛地应用在各个服务器上,如何编绎一个量身定制的nginx环境,相信大家都非常感兴趣,本文将详细介绍 Nginx编绎时的各项参数,不同的版本,参数可能会有变化,请大家不要盲目套用。

编绎环境:CentOS 7.2

源代码版本:nginx-1.14.0.tar.gz


一、准备工作

1.获得源代码包#wget http://nginx.org/download/nginx-1.14.0.tar.gz(最新源码包可在http://nginx.org/上获取)

2.解压源代码包#tar zxvf nginx-1.14.0.tar.gz

3.获得编绎参数帮助#./configure --help,获得的信息如下


  --help                             print this message
  --prefix=PATH                      set installation prefix
  --sbin-path=PATH                   set nginx binary pathname
  --modules-path=PATH                set modules path
  --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
  --build=NAME                       set build name
  --builddir=DIR                     set build directory
  --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-threads                     enable thread pool support
  --with-file-aio                    enable file AIO support
  --with-http_ssl_module             enable ngx_http_ssl_module
  --with-http_v2_module              enable ngx_http_v2_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_xslt_module=dynamic    enable dynamic ngx_http_xslt_module
  --with-http_image_filter_module    enable ngx_http_image_filter_module
  --with-http_image_filter_module=dynamic
                                     enable dynamic ngx_http_image_filter_module
  --with-http_geoip_module           enable ngx_http_geoip_module
  --with-http_geoip_module=dynamic   enable dynamic 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_gunzip_module          enable ngx_http_gunzip_module
  --with-http_gzip_static_module     enable ngx_http_gzip_static_module
  --with-http_auth_request_module    enable ngx_http_auth_request_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_slice_module           enable ngx_http_slice_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_mirror_module       disable ngx_http_mirror_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_grpc_module         disable ngx_http_grpc_module
  --without-http_memcached_module    disable ngx_http_memcached_module
  --without-http_limit_conn_module   disable ngx_http_limit_conn_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_hash_module
                                     disable ngx_http_upstream_hash_module
  --without-http_upstream_ip_hash_module
                                     disable ngx_http_upstream_ip_hash_module
  --without-http_upstream_least_conn_module
                                     disable ngx_http_upstream_least_conn_module
  --without-http_upstream_keepalive_module
                                     disable ngx_http_upstream_keepalive_module
  --without-http_upstream_zone_module
                                     disable ngx_http_upstream_zone_module
  --with-http_perl_module            enable ngx_http_perl_module
  --with-http_perl_module=dynamic    enable dynamic 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=dynamic                enable dynamic 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-stream                      enable TCP/UDP proxy module
  --with-stream=dynamic              enable dynamic TCP/UDP proxy module
  --with-stream_ssl_module           enable ngx_stream_ssl_module
  --with-stream_realip_module        enable ngx_stream_realip_module
  --with-stream_geoip_module         enable ngx_stream_geoip_module
  --with-stream_geoip_module=dynamic enable dynamic ngx_stream_geoip_module
  --with-stream_ssl_preread_module   enable ngx_stream_ssl_preread_module
  --without-stream_limit_conn_module disable ngx_stream_limit_conn_module
  --without-stream_access_module     disable ngx_stream_access_module
  --without-stream_geo_module        disable ngx_stream_geo_module
  --without-stream_map_module        disable ngx_stream_map_module
  --without-stream_split_clients_module
                                     disable ngx_stream_split_clients_module
  --without-stream_return_module     disable ngx_stream_return_module
  --without-stream_upstream_hash_module
                                     disable ngx_stream_upstream_hash_module
  --without-stream_upstream_least_conn_module
                                     disable ngx_stream_upstream_least_conn_module
  --without-stream_upstream_zone_module
                                     disable ngx_stream_upstream_zone_module
  --with-google_perftools_module     enable ngx_google_perftools_module
  --with-cpp_test_module             enable ngx_cpp_test_module
  --add-module=PATH                  enable external module
  --add-dynamic-module=PATH          enable dynamic external module
  --with-compat                      dynamic modules compatibility
  --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-pcre-jit                    build PCRE with JIT compilation support
  --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


下面以表格形式对参数进行详细介绍

编号 参数 详细说明
1 --help 输出详细的编绎帮助信息
2 --prefix=PATH 安装目标路径,默认为/usr/local/nginx
3 --sbin-path=PATH sbin文件路径,默认为/usr/local/nginx/sbin
4 --modules-path=PATH 动态模块路径,默认为/usr/local/nginx/modules
5 --conf-path=PATH

配置文件路径,默认为/usr/local/nginx/conf

此路径必须具体到文件名,安装程序自动提取对应的目录作为配置文件目录

6

--error-log-path=PATH 错误日志路径,默认为/usr/local/nginx/logs
7 --pid-path=PATH nginx 主进程PID路径,默认为/usr/local/nginx/logs
8 --lock-path=PATH

nginx唯一性锁定路径,默认为/usr/local/nginx/logs

nginx启动时,将自动创建此文件,防止多个nginx服务同时启动

9 --user=USER 设定nginx以指定用户身份启动
10 --group=GROUP 设定nginx以指定群组身份启动
11 --build=NAME 设定一个可选的编绎名称
12 --builddir=DIR 设定一个编绎目录
13 --with-select_module

支持含有 select模式的IO多路复用功能的模块

14 --without-select_module 禁用含有 select模式的IO多路复用功能的模块
15 --with-poll_module

支持含有 poll模式的IO多路复用功能的模块

16 --without-poll_module 禁用含有 poll模式的IO多路复用功能的模块
17 --with-threads 使用线程池机制
18 --with-file-aio 使用 AIO机制操作文件
19 --with-http_ssl_module
支持使用https访问
20 --with-http_v2_module
支持HTTP2协议
21 --with-http_realip_module

支持记录原始客户端的IP信息,主要用于负载均衡模式的nginx获取真实IP

22 --with-http_addition_module
在响应内容中增加额外信息
23 --with-http_xslt_module

支持使用xslt样式表来处理xml文件

24 --with-http_xslt_module=dynamic 将xslt支持编绎为动态模块
25 --with-http_image_filter_module

支持图片过滤功能,支持缩放,旋转等操作,减少读写IO

26 --with-http_image_filter_module=dynamic 将图片过滤编绎为动态模块
27 --with-http_geoip_module

使用预编绎的 MaxMind数据库解析客户端IP地址,获取地理位置信息

28 --with-http_geoip_module=dynamic

将解析IP功能编绎为动态模块

29 --with-http_sub_module 在响应内容中进行字符串替换
30 --with-http_dav_module 为http WebDav增加PUT,DELETE,MKCOL,COPY和MOVE等方法
31 --with-http_flv_module 支持flv视频播放
32 --with-http_mp4_module 支持mp4视频播放
33 --with-http_gunzip_module 为不支持gzip模块的客户端提供解压内容
34 --with-http_gzip_static_module 支持静态压缩。动态压缩是每次输出时都先进行内容压缩,然后再读取压缩 内容输出;静态压缩则先查找是否有已经压缩好的文件,如果有则直接输出
35 --with-http_auth_request_module 支持第三方认证,判断nginx用户的访问权限
36 --with-http_random_index_module 支持随机展示主页功能(随机选取根目录下的文件进行输出,.开头的除外)
37 --with-http_secure_link_module 支持链接权限和过期时间判定,主要用于防盗链等应用
38 --with-http_degradation_module 允许在内存不足的情况下返回204或444码
39 --with-http_slice_module 对过大的文件,使用分片的形式返回给客户端
40 --with-http_stub_status_module 支持使用http来获取nginx运行状态
41 --without-http_charset_module 禁用重新编码功能(从服务端返回至客户端的内容,如果是单字节编码,可以根据charset进行重新编码)
42 --without-http_gzip_module 禁用gzip功能(从服务端返回客户端的内容,不使用gzip进行压缩)
43 --without-http_ssi_module 禁用SSI(Server Side Inside)服务端网页生成机制
44 --without-http_userid_module

禁用cookie方式设置与识别用户功能

45 --without-http_access_module 禁用deny,allow等限制用户访问的功能
46 --without-http_auth_basic_module 禁用本地认证功能(输入用户名和密码进行验证,成功后才能访问相应链接)
47 --without-http_mirror_module 禁用流量镜像功能,主要用于压力测试等
48 --without-http_autoindex_module
当前目录下没有默认索引文件时,禁止自动生成目录内文件列表
49 --without-http_geo_module
禁止使用geo指令获取客户端IP
50 --without-http_map_module 禁用使用map指令映射变量
51 --without-http_split_clients_module 禁止使用split_clients进行负载均衡
52 --without-http_referer_module 禁止处理referer头中的信息
53 --without-http_rewrite_module 禁止使用重定向指令
54 --without-http_proxy_module 禁止使用代理指令
55 --without-http_fastcgi_module 禁止将请求传递到fastcgi服务器
56 --without-http_uwsgi_module 禁止将请求传递到uwsgi服务器
57 --without-http_scgi_module 禁止将请求传递到scgi服务器
58 --without-http_grpc_module 禁止支持gRPC框架
59 --without-http_memcached_module 禁用memcached缓存页面
60 --without-http_limit_conn_module 禁用限制连接数指令
61 --without-http_limit_req_module 禁用限制请求数指令
62 --without-http_empty_gif_module 禁用生成空白gif图片指令
63 --without-http_browser_module 禁止通过识别User-Agent中的值来判断浏览器类型
64 --without-http_upstream_hash_module

禁止使用将URL进行hash方式的负载均衡(每个URL指向固定服务器)

65 --without-http_upstream_ip_hash_module

禁止使用将IP进行hash方式的负载均衡(每个用户指定固定服务器)

66 --without-http_upstream_least_conn_module 禁止使用最少连接数方式的负载均衡(当前连接数/权重,数值最小的进行跳转)
67 --without-http_upstream_keepalive_module 禁止使用长连接方式与后端进行连接
68 --without-http_upstream_zone_module 禁止使用zone方式的负载均衡
69 --with-http_perl_module 支持使用perl功能
70 --with-http_perl_module=dynamic 将perl功能编绎为动态模块
71 --with-perl_modules_path=PATH 设定perl模块的路径,编绎使用
72 --with-perl=PATH 设定perl命令的路径,编绎使用
73 --http-log-path=PATH nginx服务器访问日志存储路径,具体到文件名
74 --http-client-body-temp-path=PATH 设定生成正文时的临时文件存储目录
75 --http-proxy-temp-path=PATH 设定从代理服务器收到的数据的临时存储目录
76 --http-fastcgi-temp-path=PATH 设定从fastcgi服务器收到的数据的临时存储目录
77 --http-uwsgi-temp-path=PATH 设定从uwsgi服务器收到的数据的临时存储目录
78 --http-scgi-temp-path=PATH 设定从scgi服务器收到的数据的临时存储目录
79 --without-http 禁止编绎http,只支持mail时使用此参数
80 --without-http-cache 禁止使用http的缓存机制
81 --with-mail 支持mail功能
82 --with-mail=dynamic 将mail功能编绎为动态模块
83 --with-mail_ssl_module

支持SSL方式的邮件服务器

84 --without-mail_pop3_module 禁止连接pop3方式的收件服务器
85 --without-mail_imap_module 禁止连接imap方式的收件服务器
86 --without-mail_smtp_module 禁止连接smtp方式的发件服务器
87 --with-stream 启用stream模块,主要用于四层协议的转发,代理和负载均衡
88 --with-stream=dynamic 将stream模块编绎为动态模块
89 --with-stream_ssl_module 使用https方式进行连接
90 --with-stream_realip_module

启用用户端IP地址转发

91 --with-stream_geoip_module 支持预编绎的MaxMind数据库,获取地理位置信息
92 --with-stream_geoip_module=dynamic 将支持地理位置获取功能编绎为动态模块
93 --with-stream_ssl_preread_module 在预读阶段从ClientHello消息中提取信息
94 --without-stream_limit_conn_module 禁用限制连接数指令
95 --without-stream_access_module 禁用deney,allow等指令来限制访问
96 --without-stream_geo_module

禁止使用geo指令获取IP信息

97 --without-stream_map_module 禁止使用map指令映射变量
98 --without-stream_split_clients_module 禁止使用split_clients进行负载均衡
99 --without-stream_return_module 禁止使用return指令向客户端发送信息
100 --without-stream_upstream_hash_module

禁止使用将URL进行hash方式的负载均衡(每个URL指向固定服务器)

101 --without-stream_upstream_least_conn_module 禁止使用最少连接数方式的负载均衡(当前连接数/权重,数值最小的进行跳转)
102 --without-stream_upstream_zone_module 禁止使用zone方式的负载均衡
103 --with-google_perftools_module 启用谷歌的perftools开发库
104 --with-cpp_test_module

测试C++模块中的C函数能否通过编绎

105 --add-module=PATH 启用第三方模块,使用load_module加载
106 --add-dynamic-module=PATH 启用第三方动态模块,使用load_module加载
107 --with-compat 启用动态模块兼容性
108 --with-cc=PATH 设定编绎时cc命令的路径
109 --with-cpp=PATH 设定编绎时cpp命令的路径
110 --with-cc-opt=OPTIONS 设定编绎时cc命令所需的参数
111 --with-ld-opt=OPTIONS 设定编绎连接时ld所需的参数
112 --with-cpu-opt=CPU

为特定CPU编绎版本

113 --without-pcre 禁用使用正则表达式
114 --with-pcre 支持正则表达式
115 --with-pcre=DIR 设定编绎时正则表达式开发库的路径
116 --with-pcre-opt=OPTIONS 设定编绎时正则表达式所需的参数
117 --with-pcre-jit 编绎时支持实时编绎功能
118 --with-zlib=DIR 设定编绎时zlib开发库的路径
119 --with-zlib-opt=OPTIONS 设定编时zlib所需的参数
120 --with-zlib-asm=CPU

为指定的CPU设定相应的汇编源进行优化

121 --with-libatomic 支持原子内存操作
122 --with-libatomic=DIR 设定原子内存操作开发库的路径
123 --with-openssl=DIR 设定支持openssl的开发库路径
124 --with-openssl-opt=OPTIONS 设定编绎openssl所需的参数
125 --with-debug 启用debug日志



文章分类
联系我们
联系人: powereye
Email: zqs@someapp.cn
QQ: 1134846
微信: powereye