nginx安装及编译参数详解
1.centos下Yum安装 Nginx
yum list|grep nginx 发现没有可用的结果
通过创建下面的文件在系统中添加nginx仓库的yum配置
vi /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1
wq!
然后
yum list|grep nginx
[root@localhost110 nginx-1.8.0]# yum list|grep nginx
nginx.x86_64 1.8.1-1.el6.ngx nginx
nginx-debug.x86_64 1.8.0-1.el6.ngx nginx
nginx-debuginfo.x86_64 1.8.1-1.el6.ngx nginx
nginx-nr-agent.noarch 2.0.0-9.el6.ngx nginx
就可以用yum install nginx来安装了
2.源码方式安装
Nginx代码提供2个独立的下载分支,标准版和开发版
开发分支是一个处于积极开发状态的版本,都可以用于生产环境,主要区别在于对第三方模块的支持
在开发版本内部的api可能会发生改变,而标准版的却保持不变
因此,为了向下兼容第三方模块,在标准版中第三方模块都可以有效使用
下载源码包,解压 编译安装即可
编译通用配置选项见下表
|
选项 |
解释说明 |
|
--prefix=<path> |
Nginx安装的根路径,所有其它路径都要依赖该选项 |
|
--sbin-path=<path> |
指定nginx二进制文件的路径,没指定的话 这个路径依赖--prefix选项 |
|
--conf-path=<path> |
如果在命令行未指定配置文件,那么将会通过这里指定的路径,nginx将会去那里查找他的配置文件 |
|
--error-log-path=<path> |
错误文件路径,nginx写入错误日志文件地址,除非有其他配置 |
|
--pid-path=<path> |
nginx master进程pid写入的文件位置,通常在var/run下 |
|
--lock-path=<path> |
共享存储器互斥锁文件路径 |
|
--user=<user> |
worker进程运行的用户 |
|
--group=<group> |
worker进程运行的组 |
|
--with-file-aio. |
为freeBSD4.3+和linux2.6.22+系统启用异步io |
|
--width-debug |
启用调试日志,生产环境不推荐 |
nginx -V 查看编译参数
nginx version: nginx/1.8.
built by gcc 4.4. (Red Hat 4.4.-) (GCC)
built with OpenSSL 1.0.1e-fips Feb
TLS SNI support enabled
configure arguments: --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-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'
即为
--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-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'
优化编译参数 见下表
|
选项 |
说明 |
|
--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库文件路径 |
对于典型的mail代理,nginx配置可为
./configure --with-mail --with-mail_ssl_module --with-openssl=${BUILD_DIR}/openssl-1.0.1c
指定路径的配置选项
下边显示了http模块有效的配置选项,从激活perl模块到临时目录的位置
|
选项 |
说明 |
|
--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临时文件路径 |
|
--http-fastcgi-temp-path=PATH |
set path to store http fastcgi temporary files |
|
--http-scgi-temp-path=PATH |
set path to store http scgi temporary files |
使用各种模块
在nginx发布的版本中,除了http和mail模块之外,还有一些其他模块在默认安装时并没有被安装
可通过以下配置来启用相应的选项
http模块配置选项
|
选项 |
说明 |
|
--with-http_ssl_module |
如果需要对流量加密.可使用此选项,在urls中开始部分将会是https(需要openssl库) |
|
--with-http_realip_module |
允许ngx_http_realip_module模块(mod_rpaf) 此模块支持显示真实来源IP地址,主要用于NGINX做前端负载均衡服务器使用, 如果你的nginx在七层负载均衡器或者其它设备之后,它们将Http头中的客户端ip地址传递,这时需要启用此模块,在多个客户处于一个ip地址的情况下使用 |
|
--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的运行状态,如果是工业状况,可以直接取消 输出的状态信息科使用RRDtool或类似的工具绘制成图 |
正如上表所列,这些模块都是建立在http模块基础之上的,它们提供了额外的功能。在编译时启用这些模块根本不会影响到运行性能,以后再配置使用这些模块时性能会产生影响
对于网络加速代理,就配置选项,建议以下配置
./configure --with-http_ssl_module --with-http_realip_module --with-http_geoip_module --with-http_stub_status_module --with-openssl=${BUILD_DIR}/openssl-1.0.1c
及web服务器
./configure --with-http_stub_status_module
一个简单的安装
./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=/usr/local/src/pcre-8.41 \
--with-zlib=/usr/local/src/zlib-1.2. \
--with-openssl=/usr/local/src/openssl-1.0.1t
--with-pcre=/usr/local/src/pcre-8.41 \
--with-zlib=/usr/local/src/zlib-1.2.7 \
--with-openssl=/usr/local/src/openssl-1.0.1t
这3个是库的源码位置
等号左右不能有空格
未完待续
nginx安装及编译参数详解的更多相关文章
- Nginx安装及配置详解【转】
nginx概述 nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是一个IMAP.POP3.SMTP代理服务器:nginx可以作为一个HTTP服务器进行网站的发布处理,另外 ...
- [转帖]Nginx安装及配置详解 From https://www.cnblogs.com/zhouxinfei/p/7862285.html
Nginx安装及配置详解 nginx概述 nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是一个IMAP.POP3.SMTP代理服务器:nginx可以作为一个HTTP ...
- Linux中Nginx安装与配置详解
转载自:http://www.linuxidc.com/Linux/2016-08/134110.htm Linux中Nginx安装与配置详解(CentOS-6.5:nginx-1.5.0). 1 N ...
- ubuntu nginx 安装以及配置文件详解
1.到nginx官网下载源码包.最好下载稳定版本,nginx官网http://www.nginx.org/ 2.安装nginx依赖包运行命令: sudo apt-get install libssl- ...
- nginx安装及配置文件详解
一)nginx安装及模块讲解 1.1.nginx安装步骤 mkdir /soft wget http://nginx.org/download/nginx-1.12.0.tar.gz tar zxf ...
- Nginx安装及配置详解
nginx概述 nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是一个IMAP.POP3.SMTP代理服务器:nginx可以作为一个HTTP服务器进行网站的发布处理,另外 ...
- Nginx安装及配置详解包括windows环境
nginx概述 nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是一个IMAP.POP3.SMTP代理服务器:nginx可以作为一个HTTP服务器进行网站的发布处理,另外 ...
- Linux中Nginx安装与配置详解 test(待整理 补全)
http://www.linuxidc.com/Linux/2016-08/134110.htm http://www.cnblogs.com/freeweb/p/5425554.html http: ...
- 【转】 linux 安装nginx及编译参数详解
版权声明:本文为博主原创文章,未经博主允许不得转载. 从官网下载一个nginx 的tar.gz 版. 安装方式使用make 安装 第一步:解压 tar -zxvf nginx-1.7.4.tar.g ...
随机推荐
- Android高手进阶教程(十七)之---Android中Intent传递对象的两种方法(Serializable,Parcelable)!
[转][原文] 大家好,好久不见,今天要给大家讲一下Android中Intent中如何传递对象,就我目前所知道的有两种方法,一种是Bundle.putSerializable(Key,Object); ...
- 如何查看eclipse、mysql的版本 - 原创
Eclipse 1)如果实在官网下载的,看压缩包名字就可以看出来,只带有win32字样的是32位,带有win32-x86_64字样的是64位的. 2)找到eclipse安装目录的eclipse.ini ...
- js插件封装
插件封装原则 1.暴露出来的实例必须只能是一个 2.IIFE包裹 !执行包裹 函数作用域保护 3.实例化方法不要写在函数内 throw这个方法是报错
- Java中Collections.sort()排序详解
public static void main(String[] args) { List<String> list = new ArrayList<String>(); ...
- scala学习手记38 - 方法命名约定和for表达式
方法命名约定 之前在学习<运算符重载>一节时曾经说过一个方法命名约定:方法的第一个字符决定了方法的优先级.现在再说另一个命名约定:如果方法以冒号(:)结尾,则调用目标是运算符后面的实例. ...
- 51nod-1201-数位dp
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1201 1201 整数划分 基准时间限制:1 秒 空间限制:131072 ...
- RabbitMQ 资料整理
前言: 官方教程: https://www.rabbitmq.com/getstarted.html 应用场景(之马云赚钱): http://blog.csdn.net/whoamiyang/arti ...
- 【Hive】自定义函数
Hive的自定义函数无法满足实际业务的需要,所以为了扩展性,Hive官方提供了自定义函数来实现需要的业务场景. 1.定义 (1)udf(user defined function): 自定义函数,特 ...
- opencv:创建滑动条
函数原型: ,); #include <opencv.hpp> using namespace cv; #define WINDOW_NAME "线性混合示例" // ...
- css03层次选择器
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...