二、安装nginx
1、优化内存管理
注:Jemalloc 非必须,可以不装。该部分可以跳过。
[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]# cd ..
[root@RicenOS softwares]# rm -rf jemalloc-4.5.0
2、解压各软件包
[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_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 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 源码进行修改。
1)在开头处添加以下一行代码:
2)查找“iphp->rrp.current = iphp->selected_peer;”,将其修改为:
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/md5.h>
6、修改 nginx 版本信息
此项非必须,可以跳过。
修改以下两处为:
#define NGINX_VER "RicenOS " NGINX_VERSION
7、修改 http 请求头:
修改以下一行为:
8、修改错误页的底部:
修改以下一处为:
static u_char ngx_http_error_tail[] =
"<hr><center>RicenOS</center>" CRLF
"</body>" CRLF
"</html>" CRLF
;
9、给新版本 nginx 的 upstream 模块打上补丁
10、开始安装 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 install
未完,请继续浏览《在 Linux 系统下安装和配置 Nginx·下篇》
Copyright © 2005-2023 by www.ricensoftwares.com.cn All Rights Reserved.