您的位置:首页 > 运维架构 > Nginx

centos编译安装nginx,及其编译参数解析

2017-05-21 21:50 393 查看


先来一个简单的安装方法:


1.下载安装编译环境

yum install pcre-devel zlib-devel openssl-devel

或   yum -y groupinstall "Development Tools"

2.下载ngix代码并解压

 wget http://nginx.org/download/nginx-1.3.4.tar.gz

 tar zvxf 1.3.4.tar.gz



3.进入解压后的目录

 

cd nginx-1.3.4



4.配置nginx

./configure --prefix=/opt/nginx --with-http_stub_status_module

解释: --prefix 为安装路径,--with-为需要安装的模块,具体可以运行./configure --help 查看有效模块

5.编译并安装 nginx

make && make install

6.启动 nginx    /opt/nginx/sbin/nginx

停止 nginx      /opt/nginx/sbin/nginx -s stop

重载 nginx     /opt/nginx/sbin/nginx -s reload



方法二:


一、准备工作


1.1、安装 OpenSSL(方法自行搜索)

 

1.2、准备 pcre 库

 

pere 是为了让 nginx 支持正则表达式。只是准备,并不安装,是为了避免在64位系统中出现错误。

 

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz

tar -zxf pcre-8.30

 

1.3、准备 zlib 库 

同样只是准备,并不安装,是为了避免在64位系统中出现错误。

wget http://sourceforge.net/projects/libpng/files/zlib/1.2.6/zlib-1.2.6.tar.gz/download

tar -zxf zlib-1.2.6.tar.gz

二、编译安装

 

2.1、下载、创建临时目录

 

wget http://nginx.org/download/nginx-1.1.9.tar.gz

tar -zxf nginx-1.1.9.tar.gz

cd nginx-1.1.9

mkdir -p /var/tmp/nginx

2.2、编译与安装

 

./configure --prefix=/usr/local/nginx \

--pid-path=/var/run/nginx.pid \

--lock-path=/var/lock/nginx.lock \

--with-http_ssl_module \

--with-http_dav_module \

--with-http_flv_module \

--with-http_realip_module \

--with-http_gzip_static_module \

--with-http_stub_status_module \

--with-mail --with-mail_ssl_module \

--with-pcre=../pcre-8.30 \

--with-zlib=../zlib-1.2.6 \

--with-debug \

--http-client-body-temp-path=/var/tmp/nginx/client \

--http-proxy-temp-path=/var/tmp/nginx/proxy \

--http-fastcgi-temp-path=/var/tmp/nginx/fastcgi \

--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \

--http-scgi-temp-path=/var/tmp/nginx/scgi

make && make install

ln -s /usr/local/nginx/sbin/nginx /usr/sbin/

可参考文末:Nginx编译参数解析

 

–prefix #nginx安装目录,默认在/usr/local/nginx

  –pid-path #pid问件位置,默认在logs目录

 –lock-path #lock问件位置,默认在logs目录

 –with-http_ssl_module #开启HTTP SSL模块,以支持HTTPS请求。

 –with-http_dav_module #开启WebDAV扩展动作模块,可为文件和目录指定权限

 –with-http_flv_module #支持对FLV文件的拖动播放

 –with-http_realip_module #支持显示真实来源IP地址

 –with-http_gzip_static_module #预压缩文件传前检查,防止文件被重复压缩

 –with-http_stub_status_module #取得一些nginx的运行状态

 –with-mail #允许POP3/IMAP4/SMTP代理模块

 –with-mail_ssl_module #允许POP3/IMAP/SMTP可以使用SSL/TLS

  –with-pcre=../pcre-8.11 #注意是未安装的pcre路径

 –with-zlib=../zlib-1.2.5 #注意是未安装的zlib路径

 –with-debug #允许调试日志

 –http-client-body-temp-path #客户端请求临时文件路径

 –http-proxy-temp-path #设置http proxy临时文件路径

 –http-fastcgi-temp-path #设置http fastcgi临时文件路径

 –http-uwsgi-temp-path=/var/tmp/nginx/uwsgi #设置uwsgi 临时文件路径

 –http-scgi-temp-path=/var/tmp/nginx/scgi #设置scgi 临时文件路径

 

2.3、开机自启动 nginx 脚本

vim /etc/init.d/nginx

进入编辑模式,键入以下脚本内容:

#!/bin/bash 



#chkconfig: - 85 15 

#description: Nginx is a World Wide Web server. 

#processname: nginx 

nginx=/usr/local/nginx/sbin/nginx 

conf=/usr/local/nginx/conf/nginx.conf 

case $1 in 

       start) 

              echo -n "Starting Nginx" 

              $nginx -c $conf 

              echo " done" 

       ;; 

       stop) 

              echo -n "Stopping Nginx" 

              killall -9 nginx 

              echo " done" 

       ;; 

       test) 

              $nginx -t -c $conf 

       ;; 

        reload) 

              echo -n "Reloading Nginx" 

              ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP 

              echo " done" 

       ;; 

        restart) 

                $0 stop 

                $0 start 

       ;; 

       show) 

              ps -aux|grep nginx 

       ;; 

       *) 

              echo -n "Usage: $0 {start|restart|reload|stop|test|show}" 

       ;; 

esac

保存以上脚本后,执行以下操作

chkmod +x /etc/init.d/nginx

chkconfig --add nginx 

chkconfig nginx on


附录:nginx虚拟主机配置

server {

 listen      80;

 server_name vps.xj123.info;

 location / {

 root   html/vps;

 index index.html index.htm;

     }

 }

 

提示:可以使用nginx -t来检验语法是否有问题,如图所示:




 


nginx编译参数解析

/configure --help
 
--help 显示本提示信息
 
--prefix=PATH 设定安装目录
 
--sbin-path=PATH 设定程序文件目录
 
--conf-path=PATH 设定配置文件(nginx.conf)目录
 
--error-log-path=PATH 设定错误日志目录
 
--pid-path=PATH 设定pid文件(nginx.pid)目录
 
--lock-path=PATH 设定lock文件(nginx.lock)目录
 
--user=USER 设定程序运行的用户环境(www)
 
--group=GROUP 设定程序运行的组环境(www)
 
--builddir=DIR 设定程序编译目录
 
--with-rtsig_module 允许rtsig模块
 
rtsig模块是一种实时信号,在Linux 2.2.19 默认情况下,实时信号连接数不超过1024,但是对于高负载是肯定不够的。因此通过调整内核参数/proc/sys/kernel/rtsig-max达到效果。但是Linux 2.6.6-mm2开始,这个参数不再可用,并为每个进程有一个独立的信号队列,数字是由RLIMIT_SIGPENDING确定。当队列变得满载时,nginx开始抛弃连接并使用poll方法,直到负载恢复正常。
 
--with-select_module 允许select模块(一种轮询模式,不推荐用在高载环境)
 
--without-select_module 不使用select模块
 
标准连接模式。默认情况下自动编译方式。您可以启用或禁用通过使用-select_module和不带- select_module配置参数这个模块。
 
--with-poll_module 允许poll模块(一种轮询模式,不推荐用在高载环境)
 
标准连接模式。默认情况下自动编译方式。
 
--without-poll_module 不使用poll模块
 
--with-http_ssl_module 允许ngx_http_ssl_module模块(Apache对应:mod_ssl)
 
--with-http_realip_module 允许ngx_http_realip_module模块(mod_rpaf)
 
此模块支持显示真实来源IP地址,主要用于NGINX做前端负载均衡服务器使用。
 
--with-http_addition_module 允许ngx_http_addition_module模块(mod_layout)
 
游戏服务器不必安装,门户网站可以安装,有利于被搜索引擎收录页面信息。
 
--with-http_xslt_module 允许ngx_http_xslt_module模块
 
这个模块是一个过滤器,它可以通过XSLT模板转换XML应答。0.7.8后面版本才可以使用。
 
--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_gzip_static_module 允许ngx_http_gzip_static_module模块(mod_dflate)。
 
这个模块在一个预压缩文件传送到开启Gzip压缩的客户端之前检查是否已经存在以“.gz”结尾的压缩文件,这样可以防止文件被重复压缩。
 
--with-http_random_index_module 允许ngx_http_random_index_module模块(mod_autoindex),从目录中选择一个随机主页
 
--with-http_stub_status_module 允许ngx_http_stub_status_module模块(mod_status)
 
这个模块可以取得一些nginx的运行状态,如果是工业状况,可以直接取消。
 
--without-http_charset_module 不使用ngx_http_charset_module模块
 
这个模块将在应答头中为"Content-Type"字段添加字符编码
 
--without-http_gzip_module 不使用ngx_http_gzip_module模块,文件压缩模式。
 
--without-http_ssi_module 不使用ngx_http_ssi_module模块,此模块处理服务器端包含文件(ssi)的处理.
 
--without-http_userid_module 不使用ngx_http_userid_module模块
 
The module ngx_http_userid_module gives out cookies for identification of clients
 
--without-http_access_module 不使用ngx_http_access_module模块
 
--without-http_auth_basic_module 不使用ngx_http_auth_basic_module模块
 
--without-http_autoindex_module 不使用ngx_http_autoindex_module模块
 
--without-http_geo_module 不使用ngx_http_geo_module模块
 
这个模块基于客户端的IP地址创建一些ngx_http_geoip_module变量,并与MaxMindGeoIP文件进行匹配,该模块仅用于0.7.63和0.8.6版本之后。但效果不太理想,对于城市的IP记录并不是特别准确,不过对于网站的来源访问区域的分析大致有一定参考性。
 
--without-http_map_module 不使用ngx_http_map_module模块
 
这个模块允许你分类或者同时映射多个值到多个不同值并储存到一个变量中,可用于页面跳转其他域名使用。
 
--without-http_referer_module 不使用ngx_http_referer_module模块
 
当一个请求头的Referer字段中包含一些非正确的字段,这个模块可以禁止这个请求访问站点。可以禁止盗链的情况发生。
 
--without-http_rewrite_module 不使用ngx_http_rewrite_module模块,跳转模块
 
--without-http_proxy_module 不使用ngx_http_proxy_module模块,代理模块
 
--without-http_fastcgi_module 不使用ngx_http_fastcgi_module模块
 
--without-http_memcached_module 不使用ngx_http_memcached_module模块
 
--without-http_limit_zone_module 不使用ngx_http_limit_zone_module模块
 
此模块可以限制并发连接,达到减少攻击的效果
 
--without-http_empty_gif_module 不使用ngx_http_empty_gif_module模块
 
这个模块在内存中保存一个能够很快传递的1×1透明GIF
 
--without-http_browser_module 不使用ngx_http_browser_module模块
 
识别客户端浏览器版本来制定计划。可以实现更加来源浏览器的版本访问不同页面的效果。
 
--without-http_upstream_ip_hash_module,不使用ngx_http_upstream_ip_hash_module模块
 
--with-http_perl_module 允许ngx_http_perl_module模块,这个模块允许nginx使用SSI调用perl或直接执行perl
 
--with-perl_modules_path=PATH 设置perl模块路径
 
--with-perl=PATH 设置perl库文件路径
 
--http-log-path=PATH 设置access log文件路径
 
--http-client-body-temp-path=PATH 设置客户端请求临时文件路径
 
--http-proxy-temp-path=PATH 设置http proxy临时文件路径
 
--http-fastcgi-temp-path=PATH 设置http fastcgi临时文件路径
 
--without-http 不使用HTTP server功能,如果只是做代理服务器,可以不提供http服务
 
--with-mail 允许POP3/IMAP4/SMTP代理模块
 
--with-mail_ssl_module 允许ngx_mail_ssl_module模块
 
这个模块使得POP3/IMAP/SMTP可以使用SSL/TLS.配置已经定义了HTTP SSL模块,但是不支持客户端证书检测
 
--without-mail_pop3_module 不允许ngx_mail_pop3_module模块
 
--without-mail_imap_module 不允许ngx_mail_imap_module模块
 
--without-mail_smtp_module 不允许ngx_mail_smtp_module模块
 
--with-google_perftools_module 允许ngx_google_perftools_module模块(调试用)
 
这个模块可以启用google性能分析工具套件,模块在版本0.6.29增加。
 
--with-cpp_test_module 允许ngx_cpp_test_module模块
 
--add-module=PATH 允许使用外部模块,以及路径
 
--with-cc=PATH 设置C编译器路径
 
--with-cpp=PATH 设置C预处理路径
 
--with-cc-opt=OPTIONS 设置C编译器参数
 
--with-ld-opt=OPTIONS 设置连接文件参数
 
--with-cpu-opt=CPU 为指定CPU优化,可选参数有:
 
pentium, pentiumpro, pentium3, pentium4,
 
athlon, opteron, sparc32, sparc64, ppc64
 
--without-pcre 不使用pcre库文件,pcre是包括 perl 兼容的正规表达式库
 
--with-pcre=DIR 设定PCRE库路径
 
--with-pcre-opt=OPTIONS 设置PCRE运行参数
 
--with-md5=DIR 设定md5库文件路径
 
--with-md5-opt=OPTIONS 设置md5运行参数
 
--with-md5-asm 使用md5源文件编译
 
--with-sha1=DIR 设定sha1库文件路径
 
sha1:安全哈希算法(Secure Hash Algorithm)主要适用于数字签名标准(Digital Signature Standard DSS)里面定义的数字签名算法(Digital Signature Algorithm DSA)。对于长度小于2^64位的消息,SHA1会产生一个160位的消息摘要。当接收到消息的时候,这个消息摘要可以用来验证数据的完整性。在传输的过程中,数据很可能会发生变化,那么这时候就会产生不同的消息摘要。
 
--with-sha1-opt=OPTIONS 设置sha1运行参数
 
--with-sha1-asm 使用sha1源文件编译
 
--with-zlib=DIR 设定zlib库文件路径
 
很多程序中的压缩或者解压缩函数都会用到这个库
 
--with-zlib-opt=OPTIONS 设置zlib运行参数
 
--with-zlib-asm=CPU 使zlib对特定的CPU进行优化,可选参数:
 
pentium, pentiumpro
 
--with-openssl=DIR 设定OpenSSL库文件路径
Openssl作为一个基于密码学的安全开发包,OpenSSL提供的功能相当强大和全面,囊括了主要的密码算法、常用的密钥和证书封装管理功能以及SSL协议,并提供了丰富的应用程序供测试或其它目的使用。
 
--with-openssl-opt=OPTIONS 设置OpenSSL运行参数
 
--with-debug 允许调试日志
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: