LNMP配置——Nginx配置 —— Nginx的访问日志

一、配置

先来看看Nginx的日志格式

#grep -A2 log_format /usr/local/nginx/conf/nginx.conf

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;

//$http_x_forwarded_for 为代理服务器的IP,如果使用了代理,则会记录IP

//$time_local为当前时间;$host为主机名;$request_uri为访问的URL地址

//$status为状态码,$http_referer为referer地址,$http_user_agent为user_agent

 

 

修改配置文件

#vi /usr/local/nginx/conf/vhost/test.com.conf

写入:

server

{

        listen 80;

        server_name test.com;

        index index.html index.htm index.php;

        root /data/nginx/test.com;

        if ($host != 'test.com' ){

                rewrite ^(.*)$ http://test.com/$1 permanent;

        }

        access_log /tmp/1.log combined_realip;

}

//使用access_log来指定日志的存储路径,最后面为日志的格式名字

 

#/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

 

二、检验测试

#curl -x127.0.0.1:80 test.com/111 - I

状态码404

 

 

#cat /tmp/1.log

127.0.0.1 

 

 

 

 

posted @ 2021-03-10 11:15  清空。  阅读(191)  评论(0)    收藏  举报