Linux10.6 Nginx訪問日志


    日志格式

    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

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM