compile nginx 1.6.0 with all modules in CentOS 6.x x64 (when with openssl encount bug)

本文讲一下nginx 1.6.0的源码安装, 遇到一个bug, 开启openssl支持时, 因为make文件的问题, 导致make错误, 后面会有如何避免这个错误的方法, 需要修改nginx代码中openssl的conf文件.

编译环境 : 

CentOS 6.x x64

依赖包大部分通过yum安装(除了google performance a tools,pcre和zlib, zlib通过nginx配置的makefile来安装).

安装依赖包.

安装google performance analysis tools的依赖包

# yum install -y libunwind-devel libunwind

安装google performance analysis tools

# wget https://googledrive.com/host/0B6NtGsLhIcf7MWxMMF9JdTN3UVk/gperftools-2.2.1.tar.gz
# tar -zxvf gperftools-2.2.1.tar.gz
# cd gperftools-2.2.1
# ./configure --prefix=/opt/gperftools-2.2.1
# make
# make install

# vi /etc/profile
export PATH=/opt/gperftools-2.2.1/bin:$PATH
export MANPATH=/opt/gperftools-2.2.1/share/man:$MANPATH

# vi /etc/ld.so.conf
/opt/gperftools-2.2.1/lib

# ldconfig
[root@db-172-16-3-150 ~]# ldconfig -p|grep gper
        libtcmalloc_minimal_debug.so.4 (libc6,x86-64) => /opt/gperftools-2.2.1/lib/libtcmalloc_minimal_debug.so.4
        libtcmalloc_minimal_debug.so (libc6,x86-64) => /opt/gperftools-2.2.1/lib/libtcmalloc_minimal_debug.so
        libtcmalloc_minimal.so.4 (libc6,x86-64) => /opt/gperftools-2.2.1/lib/libtcmalloc_minimal.so.4
        libtcmalloc_minimal.so (libc6,x86-64) => /opt/gperftools-2.2.1/lib/libtcmalloc_minimal.so
        libtcmalloc_debug.so.4 (libc6,x86-64) => /opt/gperftools-2.2.1/lib/libtcmalloc_debug.so.4
        libtcmalloc_debug.so (libc6,x86-64) => /opt/gperftools-2.2.1/lib/libtcmalloc_debug.so
        libtcmalloc_and_profiler.so.4 (libc6,x86-64) => /opt/gperftools-2.2.1/lib/libtcmalloc_and_profiler.so.4
        libtcmalloc_and_profiler.so (libc6,x86-64) => /opt/gperftools-2.2.1/lib/libtcmalloc_and_profiler.so
        libtcmalloc.so.4 (libc6,x86-64) => /opt/gperftools-2.2.1/lib/libtcmalloc.so.4
        libtcmalloc.so (libc6,x86-64) => /opt/gperftools-2.2.1/lib/libtcmalloc.so
        libprofiler.so.0 (libc6,x86-64) => /opt/gperftools-2.2.1/lib/libprofiler.so.0
        libprofiler.so (libc6,x86-64) => /opt/gperftools-2.2.1/lib/libprofiler.so

手工安装的软件记得全部加到/etc/profile和/etc/ld.so.conf

安装nginx的依赖包, 其他依赖包系统已经安装了, 如果你编译时遇到缺少的lib库, 补上即可.

# yum install -y geoip-devel geoip libatomic_ops libatomic_ops-devel openssl openssl-devel gd gd-devel

查看openssl 相关的so文件, 因为nginx编译安装时加载openssl库有BUG, 需要修改编译文件.

[root@db-172-16-3-150 nginx-1.6.0]# rpm -ql openssl-devel|grep libssl
/usr/lib64/libssl.so

下载zlib源码

# cd /opt/soft_bak
# wget http://zlib.net/zlib-1.2.8.tar.gz
# tar -zxvf zlib-1.2.8.tar.gz

下载pcre源码.

# cd /opt/soft_bak
# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.zip?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fpcre%2Ffiles%2Fpcre%2F8.35%2F&ts=1405687477&use_mirror=jaist
# unzip pcre-8.35.zip

下载nginx最后的稳定版本.

# wget http://nginx.org/download/nginx-1.6.0.tar.gz
# tar -zxvf nginx-1.6.0.tar.gz
# cd nginx-1.6.0

有个BUG, 必须先修改编译文件, 如果不修改会有BUG, 导致无法安装.

# vi auto/lib/openssl/conf
	*)
            have=NGX_OPENSSL . auto/have
            have=NGX_SSL . auto/have

            CORE_INCS="$CORE_INCS $OPENSSL/.openssl/include"
            CORE_DEPS="$CORE_DEPS $OPENSSL/.openssl/include/openssl/ssl.h"
            CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a"
            CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"
            CORE_LIBS="$CORE_LIBS $NGX_LIBDL"
改成
        *)
            have=NGX_OPENSSL . auto/have
            have=NGX_SSL . auto/have

            CORE_INCS="$CORE_INCS /usr/include/openssl"
            CORE_DEPS="$CORE_DEPS $CORE_INCS/ssl.h"
            CORE_LIBS="$CORE_LIBS /usr/lib64/libssl.so"
            CORE_LIBS="$CORE_LIBS /usr/lib64/libcrypto.so"
            CORE_LIBS="$CORE_LIBS $NGX_LIBDL"

另, pcre 编译项定制.

cd nginx-1.6.0
vi auto/lib/pcre/conf
    if [ $PCRE_JIT = YES ]; then
        have=NGX_HAVE_PCRE_JIT . auto/have
        PCRE_CONF_OPT="$PCRE_CONF_OPT --enable-jit --enable-unicode-properties --enable-utf --enable-pcre16 --enable-pcre32"
    fi

并不是使用with-pcre-opt

./configure --help
library sources DIR指源码目录, 例如, 需要pcre下载的源码.
--with-pcre=DIR                    set path to PCRE library sources

  --with-pcre-opt=OPTIONS            set additional build options for PCRE
指编译pcre的CFLAGS可选项.
[root@db-172-16-3-150 nginx-1.6.0]# grep -r with-pcre-opt *
auto/options:        --with-pcre-opt=*)               PCRE_OPT="$value"          ;;
auto/options:  --with-pcre-opt=OPTIONS            set additional build options for PCRE
[root@db-172-16-3-150 nginx-1.6.0]# grep -r PCRE_OPT *
auto/lib/pcre/make:     && CC="\$(CC)" CFLAGS="$PCRE_OPT" \\

安装所有的模块, 全部静态连接到sbin/nginx.

# ./configure --prefix=/opt/nginx1.6.0 --without-select_module --without-poll_module --with-file-aio --with-http_ssl_module --with-http_spdy_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_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_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-http_perl_module --with-mail --with-mail_ssl_module --with-google_perftools_module --with-cpp_test_module --with-pcre=/opt/soft_bak/pcre-8.35 --with-pcre-jit --with-md5-asm --with-sha1-asm --with-zlib=/opt/soft_bak/zlib-1.2.8 --with-libatomic --with-openssl=/usr/lib64 --with-cc-opt=-I/opt/gperftools-2.2.1/include --with-ld-opt=-L/opt/gperftools-2.2.1/lib

Configuration summary
  + using PCRE library: /opt/soft_bak/pcre-8.35
  + using OpenSSL library: /usr/lib64
  + md5: using OpenSSL library
  + sha1: using OpenSSL library
  + using zlib library: /opt/soft_bak/zlib-1.2.8
  + using system libatomic_ops library

  nginx path prefix: "/opt/nginx1.6.0"
  nginx binary file: "/opt/nginx1.6.0/sbin/nginx"
  nginx configuration prefix: "/opt/nginx1.6.0/conf"
  nginx configuration file: "/opt/nginx1.6.0/conf/nginx.conf"
  nginx pid file: "/opt/nginx1.6.0/logs/nginx.pid"
  nginx error log file: "/opt/nginx1.6.0/logs/error.log"
  nginx http access log file: "/opt/nginx1.6.0/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

# make
# make install

[root@db-172-16-3-150 conf]# cd /opt/nginx1.6.0
[root@db-172-16-3-150 nginx1.6.0]# ll
total 16
drwxr-xr-x 2 root root 4096 Jul 18 15:48 conf
drwxr-xr-x 2 root root 4096 Jul 18 15:48 html
drwxr-xr-x 2 root root 4096 Jul 18 15:48 logs
drwxr-xr-x 2 root root 4096 Jul 18 15:48 sbin
[root@db-172-16-3-150 nginx1.6.0]# cd conf/
[root@db-172-16-3-150 conf]# ll
total 60
-rw-r--r-- 1 root root 1034 Jul 18 15:48 fastcgi.conf
-rw-r--r-- 1 root root 1034 Jul 18 15:48 fastcgi.conf.default
-rw-r--r-- 1 root root  964 Jul 18 15:48 fastcgi_params
-rw-r--r-- 1 root root  964 Jul 18 15:48 fastcgi_params.default
-rw-r--r-- 1 root root 2837 Jul 18 15:48 koi-utf
-rw-r--r-- 1 root root 2223 Jul 18 15:48 koi-win
-rw-r--r-- 1 root root 3957 Jul 18 15:48 mime.types
-rw-r--r-- 1 root root 3957 Jul 18 15:48 mime.types.default
-rw-r--r-- 1 root root 2656 Jul 18 15:48 nginx.conf
-rw-r--r-- 1 root root 2656 Jul 18 15:48 nginx.conf.default
-rw-r--r-- 1 root root  596 Jul 18 15:48 scgi_params
-rw-r--r-- 1 root root  596 Jul 18 15:48 scgi_params.default
-rw-r--r-- 1 root root  623 Jul 18 15:48 uwsgi_params
-rw-r--r-- 1 root root  623 Jul 18 15:48 uwsgi_params.default
-rw-r--r-- 1 root root 3610 Jul 18 15:48 win-utf

# vi /etc/profile
export PATH=/opt/nginx1.6.0/sbin:/opt/gperftools-2.2.1/bin:$PATH

[root@db-172-16-3-150 ~]# which nginx
/opt/nginx1.6.0/sbin/nginx

[其他]

1. 使用自编译的perl.

http://www.perl.org/get.html#unix_like
# wget http://www.cpan.org/src/5.0/perl-5.20.0.tar.gz
# tar -xzf perl-5.20.0.tar.gz
# cd perl-5.20.0
# ./Configure --help
Usage: Configure [-dehrsEKOSV] [-f config.sh] [-D symbol] [-D symbol=value]
                 [-U symbol] [-U symbol=] [-A command:symbol...]
  -d : use defaults for all answers.
  -e : go on without questioning past the production of config.sh.
  -f : specify an alternate default configuration file.
  -h : print this help message and exit (with an error status).
  -r : reuse C symbols value if possible (skips costly nm extraction).
  -s : silent mode, only echoes questions and essential information.
  -D : define symbol to have some value:
         -D symbol         symbol gets the value 'define'
         -D symbol=value   symbol gets the value 'value'
       common used examples (see INSTALL for more info):
         -Duse64bitint            use 64bit integers
         -Duse64bitall            use 64bit integers and pointers
         -Dusethreads             use thread support
         -Dinc_version_list=none  do not include older perl trees in @INC
         -DEBUGGING=none          DEBUGGING options
         -Dcc=gcc                 choose your compiler
         -Dprefix=/opt/perl5      choose your destination
  -E : stop at the end of questions, after having produced config.sh.
  -K : do not use unless you know what you are doing.
  -O : let -D and -U override definitions from loaded configuration file.
  -S : perform variable substitutions on all .SH files (can mix with -f)
  -U : undefine symbol:
         -U symbol    symbol gets the value 'undef'
         -U symbol=   symbol gets completely empty
       e.g.:  -Uversiononly
  -A : manipulate symbol after the platform specific hints have been applied:
         -A append:symbol=value   append value to symbol
         -A symbol=value          like append:, but with a separating space
         -A define:symbol=value   define symbol to have value
         -A clear:symbol          define symbol to be ''
         -A define:symbol         define symbol to be 'define'
         -A eval:symbol=value     define symbol to be eval of value
         -A prepend:symbol=value  prepend value to symbol
         -A undef:symbol          define symbol to be 'undef'
         -A undef:symbol=         define symbol to be ''
       e.g.:  -A prepend:libswanted='cl pthread '
              -A ccflags=-DSOME_MACRO
  -V : print version number and exit (with a zero status).

# ./Configure -des -Dprefix=/opt/perl5.20.0
# make && make test
# make install

# vi /etc/profile
export PATH=/opt/perl5.20.0/bin:/opt/pcre-8.35/bin:$PATH
export MANPATH=/opt/perl5.20.0/man:/opt/pcre-8.35/share/man:$MANPATH

[root@dba ~]# which perl
/opt/perl5.20.0/bin/perl

配置项.

./configure --prefix=/opt/nginx1.6.0 --without-select_module --without-poll_module --with-file-aio --with-http_ssl_module --with-http_spdy_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_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_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-http_perl_module --with-mail --with-mail_ssl_module --with-google_perftools_module --with-cpp_test_module --with-pcre=/opt/soft_bak/pcre-8.35 --with-pcre-jit --with-md5-asm --with-sha1-asm --with-zlib=/opt/soft_bak/zlib-1.2.8 --with-libatomic --with-openssl=/usr/lib64 --with-cc-opt=-I/opt/gperftools-2.2.1/include --with-ld-opt=-L/opt/gperftools-2.2.1/lib --with-perl=/opt/perl5.20.0/bin/perl

2. 如果要添加外部的模块, 编译时使用选项 : 

--add-module=PATH                  enable an external module


3. 不建议使用--with-select_module和--with-poll_module.


在系统不支持更好的方法如kqueue, epool, rtsig或/dev/poll时会自动enable. 

--with-select_module
--without-select_module — enables or disables building a module that allows the server to work with the select() method. This module is built automatically if the platform does not appear to support more appropriate methods such as kqueue, epoll, rtsig, or /dev/poll.

--with-poll_module
--without-poll_module — enables or disables building a module that allows the server to work with the poll() method. This module is built automatically if the platform does not appear to support more appropriate methods such as kqueue, epoll, rtsig, or /dev/poll.

  --with-rtsig_module                enable rtsig module


Linux下有效的方法是epoll.

epoll — efficient method used on Linux 2.6+.



参见


http://nginx.org/en/docs/events.html





[参考]

1. http://nginx.org/en/download.html


2. http://nginx.org/en/docs/configure.html


3. http://nginx.org/en/docs/events.html




时间: 2024-09-30 08:29:40

compile nginx 1.6.0 with all modules in CentOS 6.x x64 (when with openssl encount bug)的相关文章

Nginx 1.4.0稳定版下载地址

nginx-1.4.0 稳定版发布了,该版本包含 1.3 中的所有改进,其中不少都是新特性,包括支持 WebSocket 连接的反向代理.OCSP stapling, SPDY 模块, gunzip filter 等等.Nginx 1.4.0 在 1.3.16 的基础上修复了两个 bug: *) Bugfix: nginx could not be built with the ngx_http_perl_module if the --with-openssl option was used;

Ubuntu nginx 1.6.0 服务器 nginx.conf等相关配置

环境UBUNUT 14.04  nginx:nginx 1.6.0 内存:12G 呆狐狸.风来了 等有空了再添加 注释 nginx.conf user www www; #启动进程,通常设置成和cpu的数量相等 worker_processes 4; #错误日志文件 error_log /www/wwwLogs/nginx_error.log; pid /www/lanmps/nginx/logs/nginx.pid; worker_rlimit_nofile 5120; events { us

linux下编译平滑升级Nginx 1.6.0至Nginx 1.6.1教程

本篇文章主要介绍编译无缝平滑升级Nginx 1.6.0至Nginx 1.6.1. ##下载最新软件 [root@idoseek ~]# cd /usr/local/src/ &&  wget http://nginx.org/download/nginx-1.6.1.tar.gz &&  tar -zxvf nginx-1.6.1.tar.gz    ##解压并根据原参数编译 [root@idoseek nginx-1.6.1]# cd nginx-1.6.1 &&

nginx 1.8.0下载

nginx 1.8.0下载地址: http://nginx.org/download/nginx-1.8.0.tar.gz  参考: http://blog.csdn.net/hhq163/article/details/46548151

Joomla, PHP, Nginx, PostgreSQL, fpm on CentOS 6.4 x64

本文介绍一下Joomla的安装和配置. 环境 :  CentOS  6.x x64 PHP # rpm -qa|grep php php-pdo-5.4.30-1.el6.remi.x86_64 php-gd-5.4.30-1.el6.remi.x86_64 php-fpm-5.4.30-1.el6.remi.x86_64 php-common-5.4.30-1.el6.remi.x86_64 php-5.4.30-1.el6.remi.x86_64 php-extras-debuginfo-5

mediawiki, nginx, PHP, PostgreSQL, zhparser on CentOS 6.4 x64

本文介绍一下如何部署wiki网站. 目前wikimedia网站的架构 :    本文测试环境 :  CentOS 6.x x64 mediawiki 1.23.1 php 5.5.14 nginx 1.6.0 PostgreSQL 9.3.x zhparser 中文分词 选择mediawiki 的 lts版本.  # wget http://releases.wikimedia.org/mediawiki/1.23/mediawiki-1.23.1.tar.gz # tar -zxvf medi

compile httpd 2.4.9, perl, php in CentOS 6.x x64

httpd 2.4.9 在CentOS 6.x x64上的安装过程. 一. apr安装 http://apr.apache.org/download.cgi # wget http://mirror.bit.edu.cn/apache//apr/apr-1.5.1.tar.bz2 # tar -jxvf apr-1.5.1.tar.bz2 # cd apr-1.5.1 # ./configure --prefix=/opt/apr1.5.1 # make && make test # ma

CentOS 6.5 x64系统中安装MongoDB 2.6.0二进制发行版教程_MongoDB

MongoDB的国外镜像访问非常慢,以至于选择MongoDB官网的在线安装很不靠谱.那么,我们可以选择安装MongoDB 2.6的二进制发布包. 下面我们在CentOS 6.5 x64系统上安装最新的MongoDB 2.6.0二进制发行版. 1.下载MongoDB 2.6.0二进制发行版 复制代码 代码如下: $ curl -O http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.6.0.tgz 2.解压MongoDB的压缩包 复制

nginx配置yii2.0重写的例子

apache和nginx比起来,我更倾向nginx,占用资源少,且性能高,不管是开发还是生产环境都很好用.那么,如何配置nginx让其支持yii2.0的访问呢? 配置范例如下: server {     listen       80;     server_name  reson.com;     location / {         root   D:/wwwroot/reson/web;         index  index.html index.php;   if (!-e $r