可以自己定义
[root@lizhipenglinux01 vhost]# pwd
/usr/local/nginx/conf/vhost
[root@lizhipenglinux01 vhost]# vim test.com.conf
server
{
listen 80;
server_name test.com test2.com test3.com;
index index.html index.htm index.php;
root /data/wwwroot/test.com;
if ($host != 'test.com' ) {
rewrite ^/(.*)$ http://test.com/$1 permanent;
}
access_log /tmp/test.com.log aming; //增加了这一行
}
[root@lizhipenglinux01 vhost]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@lizhipenglinux01 vhost]# /usr/local/nginx/sbin/nginx -s reload
[root@lizhipenglinux01 vhost]# curl -x127.0.0.1:80 test3.com/admin/index.html -I
HTTP/1.1 301 Moved Permanently
Server: nginx/1.12.1
Date: Sun, 11 Mar 2018 21:48:47 GMT
Content-Type: text/html
Content-Length: 185
Connection: keep-alive
Location: http://test.com/admin/index.html
[root@lizhipenglinux01 vhost]# curl -x127.0.0.1:80 test2.com/admin/index.html -I
HTTP/1.1 301 Moved Permanently
Server: nginx/1.12.1
Date: Sun, 11 Mar 2018 21:48:57 GMT
Content-Type: text/html
Content-Length: 185
Connection: keep-alive
Location: http://test.com/admin/index.html
[root@lizhipenglinux01 vhost]# cat /tmp/test.com.log
127.0.0.1 - [12/Mar/2018:05:48:47 +0800] test3.com "/admin/index.html" 301 "-" "curl/7.29.0"
127.0.0.1 - [12/Mar/2018:05:48:57 +0800] test2.com "/admin/index.html" 301 "-" "curl/7.29.0"
[root@lizhipenglinux01 vhost]# crontab -e 任务计划
no crontab for root - using an empty one
0 0 * * * /bin/bash /usr/local/sbin/nginx_log_rotate.sh
[root@lizhipenglinux01 vhost]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@lizhipenglinux01 vhost]# /usr/local/nginx/sbin/nginx -s reload
[root@lizhipenglinux01 vhost]# cd /data/wwwroot/test.com/
[root@lizhipenglinux01 test.com]# ls
admin index.html
[root@lizhipenglinux01 test.com]# vim 1.gif
[root@lizhipenglinux01 test.com]# vim 2.js
[root@lizhipenglinux01 test.com]# vim 1.gif
[root@lizhipenglinux01 test.com]# vim 2.js
[root@lizhipenglinux01 test.com]# curl -x127.0.0.1:80 test.com/1.gif
ddsefsonf
[root@lizhipenglinux01 test.com]# curl -x127.0.0.1:80 test.com/2.js
jnmslmc
[root@lizhipenglinux01 test.com]#
[root@lizhipenglinux01 test.com]# curl -x127.0.0.1:80 test.com/index.html
test.com
[root@lizhipenglinux01 test.com]# cat /tmp/test.com.log
127.0.0.1 - [12/Mar/2018:06:25:41 +0800] test.com "/index.html" 200 "-" "curl/7.29.0"
[root@lizhipenglinux01 test.com]# curl -x127.0.0.1:80 test.com/index.html
test.com
[root@lizhipenglinux01 test.com]# cat /tmp/test.com.log
127.0.0.1 - [12/Mar/2018:06:25:41 +0800] test.com "/index.html" 200 "-" "curl/7.29.0"
127.0.0.1 - [12/Mar/2018:06:27:02 +0800] test.com "/index.html" 200 "-" "curl/7.29.0"
[root@lizhipenglinux01 test.com]# curl -x127.0.0.1:80 test.com/2.js
jnmslmc
[root@lizhipenglinux01 test.com]# cat /tmp/test.com.log 没有2.js的记录
127.0.0.1 - [12/Mar/2018:06:25:41 +0800] test.com "/index.html" 200 "-" "curl/7.29.0"
127.0.0.1 - [12/Mar/2018:06:27:02 +0800] test.com "/index.html" 200 "-" "curl/7.29.0"
注释掉expires
没有了cache