Nginx部署搭建&版本升级

一、部署搭建

## Nginx1.18.0安装
首先得编译环境(gcc、g++、make)的准备,其次得准备prce、zlib,前者为了重写rewrite,后者为了gzip压缩。
**1、编译环境准备**
centos平台编译环境使用如下指令
安装make:
```powershell
yum -y install gcc automake autoconf libtool make
```
安装g++:
```powershell
yum install gcc gcc-c++
```
**2、选定源文件存放目录**
建议自己在根目录建立一个softtool文件夹
```powershell
cd /softtool
```
**3、安装pcre**
https://ftp.pcre.org/pub/pcre/ 下载最新的 PCRE 源码包,使用下面命令下载编译和安装 PCRE 包:
```powershell
cd /softtool
wget https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz 
tar -zxvf pcre-8.44.tar.gz
cd pcre-8.44
./configure
make
make install
```
**4、安装zlib**
http://zlib.net/zlib-1.2.11.tar.gz 下载最新的 zlib 源码包,使用下面命令下载编译和安装 zlib包:
```powershell
cd /softtool 
wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make
make install
```
**5、安装openssl**
下载地址:https://www.openssl.org/source/openssl-1.1.1g.tar.gz
```powershell
cd /usr/local/src
wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz
tar -zxvf openssl-1.1.1g.tar.gz
```
**6、安装Nginx1.18.0**
源码下载地址:http://nginx.org/download/nginx-1.18.0.tar.gz
```powershell
cd /softtool
wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar -zxvf nginx-1.18.0.tar.gz
cd nginx-1.18.0
 
./configure --sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-file-aio \
--with-http_realip_module \
--with-http_ssl_module \
--with-pcre=/softtool/pcre-8.44 \
--with-zlib=/softtool/zlib-1.2.11 \
--with-openssl=/softtool/openssl-1.1.1g
 
make 
make install
```
--with-pcre=/usr/local/src/pcre-8.44 指的是pcre-8.44 的源码路径。
--with-zlib=/usr/local/src/zlib-1.2.11指的是zlib-1.2.11 的源码路径。
**6、启动**
确保系统的 80 端口没被其他程序占用,运行/usr/local/nginx/nginx 命令来启动 Nginx
```powershell
netstat -ano|grep 80
```
进入bin目录
./nginx     //启动
kill -9 pid   //杀死进程
./nginx -s reload    //重启

参考与:https://www.nginx.cn/install

二、版本升级

简介:一般nginx版本升级主要是用于,安全漏洞修复。

nginx版本下载地址:http://nginx.org/en/download.html

1、查看nginx版本以及openssl版本
[root@host sbin]# ./nginx -V

2、备份原来nginx程序文件(usr/local/nginx/sbin目录下)
mv nginx nginx-1.18

3、将压缩包上传到服务器进行解压,上传任意位置,没有要求,解压tar xf nginx-1.20.1.tar.gz
[root@host 下载]# cd nginx-1.20.1/

[root@hos nginx-1.20.1]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module(此处configure参数根据./nginx -V打印出来参数进行配置)

[root@host nginx-1.20.1]# make

4、复制nginx-1.20.1下的nginx到原来的nginx目录下,注意nginx-1.20.1中nginx在objs目录下而不是在sbin下面
[root@host nginx-1.20.1]# cd objs/ 
[root@host objs]# cp nginx /usr/local/nginx/sbin/

5、测试是否替换成功
[root@host sbin]# /usr/local/nginx/sbin/nginx -t
[root@host sbin]# /usr/local/nginx/sbin/nginx -V

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值