12.10 Nginx Access Log
vim/usr/local/nginx/conf/nginx.conf//Search Log_format
$remote _addr//client p (public IP)
IP $http _x_forwarded_for//proxy Server
$time _local//server local time
$host//Access host name (domain name)
$request _uri//visited URL address
$status//Status code
$http _referer//referer
$http _user_agent//user_agent
vim/usr/local/nginx/conf/vhost/test.com.conf //Edit the configuration file and add the following line to the server
----------------------------------------------------------------------------
Access_log/tmp/test.com.log Combined_realip
----------------------------------------------------------------------------
The combined_realip here is the name of the log format defined in nginx.conf
/USR/LOCAL/NGINX/SBIN/NGINX-T//Check configuration for errors
/usr/local/nginx/sbin/nginx-s Reload//reload, can also restart service
Curl-x127.0.0.1:80 Test.com-i
Cat/tmp/test.com.log
12.11 Nginx Log Cutting
vim/usr/local/sbin/nginx_log_rotate.sh//write the following:
------------------------------------------------------------------------------------
#! /bin/bash
# #假设nginx的日志存放路径为/data/logs/
D= ' date-d '-1 day +%y%m%d '//similar to 20180427, yesterday's date, today 28th
Logdir= "/data/logs"
Nginx_pid= "/usr/local/nginx/logs/nginx.pid"
CD $logdir
For log in ' ls *.log '
Do
MV $log $log-$d
Done
/bin/kill-hup ' Cat $nginx _pid '
--------------------------------------------------------------------------------------
Add Task Schedule #crontab-e//write the following:
0 0 * * */bin/bash/usr/local/sbin/nginx_logrotate.sh//Daily 0 o'clock in the morning execution
12.12 static files do not log logs and expire time
vim/usr/local/nginx/conf/vhost/test.com.conf //Edit the configuration file and add the following line to the server
--------------------------------------------------------------
Location ~. *\. (gif|jpg|jpeg|png|bmp|swf) $
{
Expires 7d;
Access_log off;
}
Location ~. *\. (JS|CSS) $
{
Expires 12h;
Access_log off;
}
--------------------------------------------------------------
Location matching; \ de-expires; expiration time; Access_log off does not log access logs;
/USR/LOCAL/NGINX/SBIN/NGINX-T//Check configuration for errors
/usr/local/nginx/sbin/nginx-s Reload//reload, can also restart service
Test
cd/data/wwwroot/test.com/
Ls
Vim 1.gif//write something casually
Vim 2.js //write something .
Curl-x127.0.0.1:80 Test.com/1.gif
Curl-x127.0.0.1:80 Test.com/2.js
Cat/tmp/test.com.log
Linux study notes 12 weeks three lessons (April 25)