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 {} \;
浙公網安備 33010602011771號