【CentOS 7架构24】,nginx访问日志#180105

来源:转载


hellopasswd





nginx访问日志
日志格式
vi /usr/local/nginx/conf/nginx.conf
除了在主配置文件nginx.conf里定义日志格式外,还需要在虚拟主机配置文件中增加
access_log /tmp/1.log combined_realip;
这里的combined_realip就是在nginx.conf中定义的日志格式名字
-t && -s reload
cat /tmp/1.log
[[email protected] vhost]# vi ../nginx.conf
/fog_format

log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
' $host "$request_uri" $status'
' "$http_referer" "$http_user_agent"';
其中combined_realip日志名
$remote addr客户端IP(公网IP)
$http_x_forwarded_for代理服务器的IP
$time_local服务器本地时间
$hostf访问主机名(域名)
$request_uri访问的url地址
$status状态码
$http_refererreferer
$http_user_agentuser_agent


添加access_log /tmp/test.com.log user;


[[email protected] vhost]# vi test.com.conf
1 server
2 {
3listen 80;
4server_name test.com test1.com test2.com;
5index index.html index.htm index.php;
6root /data/wwwroot/test.com;
7if ($host != 'test.com'){
8 rewrite ^/(.*)$ http://test.com/$1 permanent;
9}
10
11 location ~(.*)admin.php$
12{
13 auth_basic"Auth";
14 auth_basic_user_file/usr/local/nginx/conf/htpasswd;
15}
16access_log /tmp/test.com.log user;
17 }
[[email protected] 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
[[email protected] vhost]# /usr/local/nginx/sbin/nginx -s reload[[email protected] vhost]# curl -x 127.0.0.1:80 test2.com/admin/index.html -I
HTTP/1.1 301 Moved Permanently
Server: nginx/1.4.7
Date: Thu, 04 Jan 2018 08:07:12 GMT
Content-Type: text/html
Content-Length: 184
Connection: keep-alive
Location: http://test.com/admin/index.html
[[email protected] vhost]# curl -x 127.0.0.1:80 test1.com/admin/index.html -I
HTTP/1.1 301 Moved Permanently
Server: nginx/1.4.7
Date: Thu, 04 Jan 2018 08:07:16 GMT
Content-Type: text/html
Content-Length: 184
Connection: keep-alive
Location: http://test.com/admin/index.html
[[email protected] vhost]# cat /tmp/test.com.log
127.0.0.1 - - [04/Jan/2018:16:07:12 +0800] "HEAD HTTP://test2.com/admin/index.html HTTP/1.1" 301 0 "-" "curl/7.29.0"
127.0.0.1 - - [04/Jan/2018:16:07:16 +0800] "HEAD HTTP://test1.com/admin/index.html HTTP/1.1" 301 0 "-" "curl/7.29.0"

修改于 180105

分享给朋友:
您可能感兴趣的文章:
随机阅读: