优化Web服务器

优化Web服务器,实现如下效果:

自定义网站404错误页面
升级nginx至1.15.8版本,开启status模块
编写日志切割脚本,实现每周五备份日志

2.2 步骤

实现此案例需要按照如下步骤进行。

步骤一:自定义404错误页面

1)优化前测试(客户端访问一个不存在的页面)。

[root@room9pc01 ~]# firefox http://www.lab.com/git
  1. 修改Nginx配置文件,自定义错误页面

    [root@web1 ~]# vim /usr/local/nginx/conf/nginx.conf
    error_page 404 /404.html; //自定义错误页面
    [root@web2 ~]# vim /usr/local/nginx/conf/nginx.conf
    error_page 404 /404.html; //自定义错误页面
    [root@web3 ~]# vim /usr/local/nginx/conf/nginx.conf
    error_page 404 /404.html; //自定义错误页面

3) 重启nginx

[root@web1 ~]# /usr/local/nginx/sbin/nginx -s reload
[root@web2 ~]# /usr/local/nginx/sbin/nginx -s reload
[root@web3 ~]# /usr/local/nginx/sbin/nginx -s reload

步骤二:升级nginx版本,开启status模块

1)配置、编译新的nginx(web1、web2、web3做相同操作,下面以web1为例)

[root@web1 ~]# tar  -xf   nginx-1.15.8.tar.gz
[root@web1 ~]# cd  nginx-1.15.8
[root@web1 ~]# ./configure     \
--with-http_ssl_module         \
--with-http_stub_status_module
[root@web1 ~]# make
  1. 备份老版本nginx,更新新版本nginx

    [root@web1 ~]# mv /usr/local/nginx/sbin/nginx{,.bak}
    [root@web1 ~]# cp objs/nginx /usr/local/nginx/sbin/

3)修改配置文件

[root@web1 ~]# vim /usr/local/nginx/conf/nginx.conf
... ...
location /status {
                stub_status on;
                 allow 192.168.2.0/24;
                 deny all;
        }
... ...
  1. 重启服务

    [root@web1 ~]# killall nginx
    [root@web1 ~]# /usr/local/nginx/sbin/nginx

步骤三:编写日志切割脚本

1)编写脚本(以web1为例)

[root@web1 ~]# vim /usr/local/nginx/logbak.sh
#!/bin/bash
date=`date +%Y%m%d`
logpath=/usr/local/nginx/logs
mv $logpath/access.log $logpath/access-$date.log
mv $logpath/error.log $logpath/error-$date.log
kill -USR1 $(cat $logpath/nginx.pid)

2)创建计划任务

[root@web1 ~]# crontab -e
03 03 * * 5  /usr/local/nginx/logbak.sh

你可能感兴趣的:(Linux)