1.部署Nginx

开源社区:https://nginx.org

1.1下载Nginx

下载页面地址:https://nginx.org/en/download.html

linux服务器执行如下命令:

wget https://nginx.org/download/nginx-1.21.5.tar.gz

1.2解压压缩包

Linux服务器执行如下命令:

## 解压
tar -xvf nginx-1.21.5.tar.gz

1.3编译安装

## 若没安装gcc c++,执行如下命令安装,已安装则忽略
yum install gcc gcc-c++

## 若没安装make,执行如下命令安装,已安装则忽略
yum -y install gcc automake autoconf libtool make

## 安装pcre,Nginx rewrite模块需要
yum install -y pcre pcre-devel

## 安装zlib,Nginx gzip模块需要
yum install -y zlib zlib-devel

## 安装openssl,Nginx ssl需要
yum install openssl openssl-devel

## 编译安装Nginx,安装目录为/server/service/nginx
./configure --prefix=/server/service/nginx --with-http_ssl_module

## 执行make
make

## 执行make install
make install

## 启动Nginx
/server/service/nginx/sbin/nginx

1.4 Nginx 日志切割

## 安装logrotate
yum install logrotate

## 配置切割规则
cd /etc/logrotate.d/

## vim nginx
vim nginx

## 内容如下
/server/service/nginx/logs/*.log {
daily
rotate 3
missingok
notifempty
sharedscripts
postrotate
    if [ -f /server/service/nginx/logs/nginx.pid ]; then
        kill -USR1 `cat /server/service/nginx/logs/nginx.pid`
    fi
endscript
}

## 添加切割定时
crontab -e

59 23 * * *  /usr/sbin/logrotate -f /etc/logrotate.d/nginx 

## 校验日志切割
/usr/sbin/logrotate -d /etc/logrotate.d/nginx