首页 > 技术文章 > nginx编译参数的内容

justhing 2017-12-30 17:24 原文

 

最近公司安排我安装几台云服务器环境 采用nginx做反向代理;

查了一下官方文档,参数比较多,很多在上线后 可能才知道注意一下的。

编译安装nginx的话 需要安装一些前置组件;

1.gcc环境;用于编译官方下载的源码包

e.g:yum install gcc-c++

 

2.zlib库; nginx的gzip需要使用zlib库

e.g:yum install -y zlib zlib-devel

 

3.perl库-PCRE;nginx中的http模块的东西需要pcre来解析

e.g:yum install -y pcre pcre-devel

 

4.OpenSS; 提供ssl协议,部分秘钥的支持;

e.g:yum install -y openssl openssl-devel

 

 

通过wget到nginx的gz文件,然后解压。

{nginx解压路径}/configure 可以直接运行configure进行编译;注重自定义以及维护掌握的话。可以研究下编译的参数

有大部分的参数:

直接安装成功后也可以使用nginx -V查看编译参数

 

--prefix=/etc/nginx 
--sbin-path=/usr/sbin/nginx 
--conf-path=/etc/nginx/nginx.conf 
--error-log-path=/var/log/nginx/error.log 
--http-log-path=/var/log/nginx/access.log 
--pid-path=/var/run/nginx.pid 
--lock-path=/var/run/nginx.lock 
--http-client-body-temp-path=/var/cache/nginx/client_temp 
--http-proxy-temp-path=/var/cache/nginx/proxy_temp 
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp 
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp 
--http-scgi-temp-path=/var/cache/nginx/scgi_temp 
--user=nginx 
--group=nginx 
--with-http_ssl_module 
--with-http_realip_module 
--with-http_addition_module 
--with-http_sub_module 
--with-http_dav_module 
--with-http_flv_module 
--with-http_mp4_module 
--with-http_gunzip_module 
--with-http_gzip_static_module 
--with-http_random_index_module 
--with-http_secure_link_module 
--with-http_stub_status_module 
--with-http_auth_request_module 
--with-mail 
--with-mail_ssl_module 
--with-file-aio --with-ipv6 
--with-http_spdy_module 

 

官方提供的参数:

--with-cc=<path> 如果想设置一个不在默认path下的c编译器

--with-cpp=<path> 设置c预处理器的相对路径

--with-cc-opt=<options> 指定必要的include文件路径,可能d(-I<path>)指出,也可能是优化(-O4)和指定一个64位构建 (完全看不懂啊)

--with-ld-opt=<options> 包含连接库的路径和运行路径

-with-cpu-opt=<cpu> 通过该选项为特定cpu构建nginx

--with-mail 激活POP3/IMAP4/SMTP代理模块,默认未激活

--with-mail_ssl_module 允许ngx_mail_ssl_module模块 这个模块使得POP3/IMAP/SMTP可以使用SSL/TLS.配置已经定义了HTTP SSL模块,但是不支持客户端证书检测

--without-mail_pop3_module 启用mail模块后,单独禁用pop3模块

--without-mail_imap_module 启用mail模块后,单独禁用imap模块

--without-mail_smtp_module 启用mail模块后,单独禁用smtp模块

--without-http 完全禁用http模块,如果只想支持mall,可以使用此项设置

--with-openssl=DIR 设定OpenSSL库文件路径

--without-http-cache 在使用upstream模块时,nginx能够配置本地缓存内容,此选项可禁用缓存

--with-http_perl_module 这个模块允许nginx使用SSI调用perl或直接执行perl(使用会降低性能)

--with-perl_modules_path=PATH 设置perl模块路径(perl解析器路径)

--with-perl_modules_path=PATH 设置perl模块路径

--http-log-path=PATH 设置access log文件路径

--http-client-body-temp-path=PATH 设置客户端请求临时文件路径,如果WebDAV启用,推荐设置该路径为同一文件系统上的目录作为最终的目的地

--http-proxy-temp-path=PATH 代理设置后,设置http proxy临时文件路径

--http-fastcgi-temp-path=PATH 设置http fastcgi临时文件路径

--with-http_ssl_module 如果需要对流量加密.可使用此选项,在urls中开始部分将会是https(需要openssl库)

--with-http_realip_module 允许ngx_http_realip_module模块(mod_rpaf)

--with-http_addition_module 作为一个输出过滤器,使你能够在请求经过一个location前或后时在该location本身添加内容

--with-http_xslt_module 这个模块是一个过滤器,它可以通过XSLT模板转换XML应答

--with-http_image_filter_module 图像过滤器,在将图像投递到客户之前进行处理(需要libgd库)

--with-http_geoip_module 使用该模块使用该模块,能够设置设置个中变量以便在配置区段中使用

--with-http_sub_module 允许ngx_http_sub_module模块,这个模块可以能够在nginx的应答中搜索并替换文本

--with-http_dav_module 允许ngx_http_dav_module模块(mod_dav) 为文件和目录指定权限,限制不同类型的用户对于页面有不同的操作权限

--with-http_flv_module 允许ngx_http_flv_module模块(mod_flvx) 这个模块支持对FLV(flash)文件的拖动播放

--with-http_mp4_module 支持H.264/AAC文件为伪流媒体

--with-http_gzip_static_module 允许ngx_http_gzip_static_module模块(mod_dflate) 这个模块在一个预压缩文件传送到开启Gzip压缩的客户端之前检查是否已经存在以“.gz”结尾的压缩文件,这样可以防止文件被重复压缩

--with-http_gunzip_module 对于不支持gzip编码的客户,该模块用于为客户解压缩预压缩内容

--with-http_random_index_module 允许ngx_http_random_index_module模块(mod_autoindex),从目录中选择一个随机主页

--with-http_secure_link_module 该模块提供一种机制,它会将一个哈希值链接到一个url中,因此,只有那些使用正确的密码能够计算链接

--with-http_stub_status_module 这个模块可以取得一些nginx的运行状态,如果是工业状况,可以直接取消

 

 大部分模块并不一定要设置;具体需要根据业务场景以及业务类型去做具体的设置;

推荐阅读