Nginx安装配置、版本升降级

模块依赖性

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
5、预编译、编译、安装

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

make
make install
使用浏览器访问http://192.168.241.132出现测试页面即可。

-----------------------------------------------------------------------------------------------------------------------------

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


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值