日志格式
vim /usr/local/nginx/conf/nginx.conf //搜索log_format
| $remote_addr | 客戶端IP(公網IP) |
| $http_x_forwarded_for | 代理服務器的IP |
| $time_local | 服務器本地時間 |
| $host | 訪問主機名(域名) |
| $request_uri | 訪問的url地址 |
| $status | 狀態碼 |
| $http_referer | referer |
| $http_user_agent | user_agent |
主配置文件配置格式名為 combined_realip 格式的訪問日志
log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
' $host "$request_uri" $status'
' "$http_referer" "$http_user_agent"';
除了在主配置文件nginx.conf里定義日志格式外,還需要在虛擬主機配置文件中server塊中增加,后面的combined_realip為日志格式名字,在主配置文件中配置
access_log /tmp/1.log combined_realip;
這里的combined_realip就是在nginx.conf中定義的日志格式名字
-t && -s reload
curl -x127.0.0.1:80 test.com -I
cat /tmp/1.log
