1、配置用户
[root@localhost ~]# groupadd nginx
[root@localhost ~]# useradd -g nginx -s /sbin/nologin nginx
2、安装依赖包
[root@localhost ~]# yum -y update
[root@localhost ~]# yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel gcc lrzsz telnet wget unzip
3、解压安装包
[root@localhost ~]# tar zxvf nginx-1.10.3.tar.gz [root@localhost ~]# cd nginx-1.10.3
4、编译安装
[root@localhost nginx-1.10.2]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module [root@localhost nginx-1.10.2]# make && make install
5、配置nginx
[root@localhost ~]# vi /usr/local/nginx/conf/nginx.conf
ulimit -n 65536 同时打开文件数
日志切割删除脚本:
vi /usr/local/nginx/sbin/cut_nginx_log.sh
#!/bin/bash
## Nginx 日志文件所在的目录
LOGS_PATH=/usr/local/nginx/logs
## 获取昨天的 yyyy-MM-dd
YESTERDAY=$(date -d "yesterday" +%Y-%m-%d)
## 移动文件
mv ${LOGS_PATH}/access.log ${LOGS_PATH}/access_${YESTERDAY}.log
mv ${LOGS_PATH}/error.log ${LOGS_PATH}/error_${YESTERDAY}.log
## 向 Nginx 主进程发送 USR1 信号。USR1 信号是重新打开日志文件
kill -USR1 $(cat /usr/local/nginx/logs/nginx.pid)
crontab -e
00 00 * * * /bin/bash /usr/local/nginx/sbin/cut_nginx_log.sh
1 5 * * * /usr/bin/find /usr/local/nginx/logs -type f -mtime +3 -exec /bin/rm -r {} \;