当前位置:首页 > Nginx
在 Linux 系统下安装和配置 Nginx·中篇
来源:靑龍一笑的博客  作者:靑龍一笑  发布时间:2017-01-06 12:54:17  点击量:1840  评论:0

二、安装nginx

    1、优化内存管理
    注:Jemalloc 非必须,可以不装。该部分可以跳过。

[root@RicenOS softwares]# tar xvf jemalloc-4.5.0.tar.bz2
[root@RicenOS softwares]# cd jemalloc-4.5.0
[root@RicenOS jemalloc-4.5.0]# ./configure
[root@RicenOS jemalloc-4.5.0]# make
[root@RicenOS jemalloc-4.5.0]# make install
[root@RicenOS jemalloc-4.5.0]# vi /etc/ld.so.conf

    把“/usr/local/lib”加到第一行。

[root@RicenOS jemalloc-4.5.0]# ldconfig
[root@RicenOS jemalloc-4.5.0]# cd ..
[root@RicenOS softwares]# rm -rf jemalloc-4.5.0

    2、解压各软件包

[root@RicenOS softwares]# tar xvf nginx-1.12.0.tar.gz
[root@RicenOS softwares]# tar xvf nginx-sticky-module-1.1.tar.gz
[root@RicenOS softwares]# unzip nginx_upstream_check_module-master.zip
[root@RicenOS softwares]# tar xvf pcre-8.40.tar.gz
[root@RicenOS softwares]# tar xvf openssl-1.0.2k.tar.gz
[root@RicenOS softwares]# tar xvf zlib-1.2.11.tar.gz

    3、整理要编译的软件包

[root@RicenOS softwares]# mv nginx-sticky-module-1.1/ nginx-1.12.0
[root@RicenOS softwares]# mv nginx_upstream_check_module-master nginx-1.12.0
[root@RicenOS softwares]# mv pcre-8.40 nginx-1.12.0
[root@RicenOS softwares]# mv openssl-1.0.2k nginx-1.12.0
[root@RicenOS softwares]# mv zlib-1.2.11 nginx-1.12.0

    4、准备 pcre、openssl、zlib

[root@RicenOS softwares]# cd nginx-1.12.0/pcre-8.40/
[root@RicenOS pcre-8.40]# ./configure --enable-utf8
[root@RicenOS pcre-8.40]# make
[root@RicenOS pcre-8.40]# cd ../openssl-1.0.2k/
[root@RicenOS openssl-1.0.2k]# ./config
[root@RicenOS openssl-1.0.2k]# make
[root@RicenOS openssl-1.0.2k]# cd ../zlib-1.2.11/
[root@RicenOS zlib-1.2.11]# ./configure
[root@RicenOS zlib-1.2.11]# make
[root@RicenOS zlib-1.2.11]# cd ..

    5、修改 sticky 源码
    由于 sticky 模块已经很久没有更新了,新版本 nginx 在编译时会有问题。因此,需要在编译 nginx 前,对 sticky 源码进行修改。

[root@RicenOS nginx-1.12.0]# vi nginx-sticky-module-1.1/ngx_http_sticky_module.c

    1)在开头处添加以下一行代码:

#include <nginx.h>

    2)查找“iphp->rrp.current = iphp->selected_peer;”,将其修改为:

                #if defined(nginx_version) && nginx_version >= 1009000
                        iphp->rrp.current = peer;
                #else
                        iphp->rrp.current = iphp->selected_peer;
                #endif
[root@RicenOS nginx-1.12.0]# vi nginx-sticky-module-1.1/ngx_http_sticky_misc.c

    在开头处添加以下代码:

#include <openssl/sha.h>
#include <openssl/md5.h>

    6、修改 nginx 版本信息
    此项非必须,可以跳过。

[root@RicenOS nginx-1.12.0]# vi src/core/nginx.h

    修改以下两处为:

#define NGINX_VERSION      "1.0"
#define NGINX_VER          "RicenOS " NGINX_VERSION

    7、修改 http 请求头:

[root@RicenOS nginx-1.12.0]# vi src/http/ngx_http_header_filter_module.c

    修改以下一行为:

static u_char ngx_http_server_string[] = "Server: RicenOS" CRLF;

    8、修改错误页的底部:

[root@RicenOS nginx-1.12.0]# vi src/http/ngx_http_special_response.c

    修改以下一处为:

static u_char ngx_http_error_tail[] =
"<hr><center>RicenOS</center>" CRLF
"</body>" CRLF
"</html>" CRLF
;

    9、给新版本 nginx 的 upstream 模块打上补丁

[root@RicenOS nginx-1.12.0]# patch -p0 < /opt/softwares/nginx-1.12.0/nginx_upstream_check_module-master/check_1.11.5+.patch

    10、开始安装 nginx

[root@RicenOS nginx-1.12.0]# ./configure --prefix=/opt/nginx \
> --with-http_realip_module --with-http_sub_module --with-http_flv_module \
> --with-http_v2_module --with-http_gzip_static_module --with-http_stub_status_module \
> --with-http_addition_module --with-http_ssl_module \
> --add-module=nginx-sticky-module-1.1/ \
> --add-module=nginx_upstream_check_module-master/ \
> --with-ld-opt="-ljemalloc" --with-openssl=openssl-1.0.2k/ \
> --with-pcre=pcre-8.40/ --with-zlib=zlib-1.2.11/

    注:如果没有使用 Jemalloc 内存管理,则去掉“--with-ld-opt="-ljemalloc"”参数。

[root@RicenOS nginx-1.12.0]# make
[root@RicenOS nginx-1.12.0]# make install

    未完,请继续浏览《在 Linux 系统下安装和配置 Nginx·下篇

版权所有 © 2005-2023 靑龍一笑的博客  Powered by C.S.Ricen
Copyright © 2005-2023 by www.ricensoftwares.com.cn  All Rights Reserved.

欢迎光临本站,这里是靑龍一笑的博客。

因资金匮乏,本站已迁到国外的免费空间,可能导致本站的访问速度较慢,由此给您带来的不便,敬请谅解。

您可以通过下方的“支持本站建设”链接,给本站提供资金支持。

Free Web Hosting