模块依赖性
gzip 模块需要zlib库
Rewrite模块需要pcre库
ssl功能需要openssl库
1、安装PCRE支持库,作用使nginx支持Rewrite功能
yum install -y zlib zlib-devel pcre-devel pcre opessl openssl-devel libtool |
2、下载Nginx源码包
wget -c -P /usr/src http://nginx.org/download/nginx-1.12.0.tar.gz |
3、解压Nginx源码包
tar zxvf /usr/src/nginx-1.12.0.tar.gz -C /usr/src/ |
4、进入解压目录,做以下配置
a.修改gcc文件取消debug功能 vi nginx-1.12.0/auto/cc/gcc 注释掉 CFLAGS="$CFLAGS -g" ------------------------------------------------------------------------------------------------ b.修改Nginx版本头信息 vim nginx-1.12.0/src/http/ngx_http_header_filter_module.c 找到以下两行 49 static u_char ngx_http_server_string[] = "Server: nginx" CRLF; 50 static u_char ngx_http_server_full_string[] = "Server: " NGINX_VER CRLF; 修改为 static u_char ngx_http_server_string[] = "Server: Scott Web Server" CRLF; static u_char ngx_http_server_full_string[] = "Server: Scott Web Server" CRLF; ------------------------------------------------------------------------------------------------ c.修改Nginx版本信息 sed -i -e 's/1.12.0//g' -e 's/nginx\//Scott Web Server/g' -e 's/"NGINX"/"Scott Web Server"/g' nginx-1.12.0/src/core/nginx.h 或 vim nginx-1.12.0/src/core/nginx.h 找到以下三行 #define NGINX_VERSION "1.12.0" #define NGINX_VER "nginx/" NGINX_VERSION #define NGINX_VAR "NGINX" 修改为 #define NGINX_VERSION "" #define NGINX_VER "Scott Web Server" NGINX_VERSION #define NGINX_VAR "Scott Web Server" ------------------------------------------------------------------------------------------------ 测试: [root@ihstest02 ~]# curl -I http://192.168.241.132 HTTP/1.1 200 OK Server: Scott Web Server Date: Thu, 04 Jan 2018 03:35:26 GMT Content-Type: text/html Content-Length: 612 Last-Modified: Thu, 04 Jan 2018 03:27:19 GMT Connection: keep-alive ETag: "5a4d9f17-264" Accept-Ranges: bytes |
cd /usr/src/nginx-1.12.0 ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module makemake install |
-----------------------------------------------------------------------------------------------------------------------------
Nginx版本升降级
步骤:包括软件下载、预编译、编译、配置,具体操作如下:
1.获取新版本安装包 wget -c -P /usr/src http://www.nginx.org/download/nginx-1.13.0.tar.gz 2.查看当前版本 /usr/local/nginx/sbin/nginx -v nginx version: Scott Web Server1.12.0 3.编译新版本nginx tar zxvf /usr/src/nginx-1.13.0.tar.gz -C /usr/src/ cd /usr/src/nginx-1.13.0 ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module make 备份旧版本的可执行文件,复制新版本的nginx可执行文件 mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old cp objs/nginx /usr/local/nginx/sbin/ 4.测试新版本nginx是否正常 /usr/local/nginx/sbin/nginx -t 5.重启nginx /usr/local/nginx/sbin/nginx -s stop /usr/local/nginx/sbin/nginx 6.查看nginx是否升级成功 /usr/local/nginx/sbin/nginx -v |