域名跳转及不记录制定文件类型日志
server
{
listen 80;
server_name www.yanghao.com www.yangqiding.com www.yangteng.com;
#域名跳转
if ($host != 'www.yanghao.com')
{
rewrite ^/(.*)$ http://www.yanghao.com/$1 permanent;
}
index index.html index.htm index.php;
root /data/www;
access_log /tmp/access.log yanghao;
location ~ .*admin\.php$ {
auth_basic "yangqiding auth";
auth_basic_user_file /usr/local/nginx/conf/.htpasswd;
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
#制定不记录文件类型
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
access_log off;
}
location ~ (static|cache)
{
access_log off;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
# fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
}
日志切割
编写日志切割脚本
vim /usr/local/sbin/nginx_logrotate.sh
#!/bin/bash
d=`date -d "-1 day" +%F` #定义切割脚本的格式
[ -d /tmp/nginx_log ] || mkdir /tmp/nginx_log #检查此目录,如果没有就新建
mv /tmp/access.log /tmp/nginx_log/$d.log #移动切割后的日志到新的目录下
/etc/init.d/nginx reload > /dev/null
cd /tmp/nginx_log/
gzip -f $d.log #压缩切割后的额脚本
脚本写完后执行sh -x /usr/local/sbin/nginx_logrotate.sh
server
{
listen 80;
server_name www.yanghao.com www.yangqiding.com www.yangteng.com;
#域名跳转
if ($host != 'www.yanghao.com')
{
rewrite ^/(.*)$ http://www.yanghao.com/$1 permanent;
}
index index.html index.htm index.php;
root /data/www;
access_log /tmp/access.log yanghao;
location ~ .*admin\.php$ {
auth_basic "yangqiding auth";
auth_basic_user_file /usr/local/nginx/conf/.htpasswd;
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
#制定不记录文件类型
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
access_log off;
}
location ~ (static|cache)
{
access_log off;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
# fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
}
日志切割
编写日志切割脚本
vim /usr/local/sbin/nginx_logrotate.sh
#!/bin/bash
d=`date -d "-1 day" +%F` #定义切割脚本的格式
[ -d /tmp/nginx_log ] || mkdir /tmp/nginx_log #检查此目录,如果没有就新建
mv /tmp/access.log /tmp/nginx_log/$d.log #移动切割后的日志到新的目录下
/etc/init.d/nginx reload > /dev/null
cd /tmp/nginx_log/
gzip -f $d.log #压缩切割后的额脚本
脚本写完后执行sh -x /usr/local/sbin/nginx_logrotate.sh
编辑回复