nginx日志配置


1.在nginx.conf配置,配置在http標簽內

http {

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

}

字段意義


    $remote_addr  #記錄訪問網站的客戶端地址
    $remote_user  #遠程客戶端用戶名
    $time_local  #記錄訪問時間與時區
    $request  #用戶的http請求起始行信息
    $status  #http狀態碼,記錄請求返回的狀態碼,例如:200301、404等
    $body_bytes_sent  #服務器發送給客戶端的響應body字節數
    $http_referer  #記錄此次請求是從哪個連接訪問過來的,可以根據該參數進行防盜鏈設置。
    $http_user_agent  #記錄客戶端訪問信息,例如:瀏覽器、手機客戶端等
    $http_x_forwarded_for  #當前端有代理服務器時,設置web節點記錄客戶端地址的配置,此參數生效的前提是代理服務器也要進行相關的x_forwarded_for設置

 

2.使配置生效,配置在server標簽內(針對某站點配置)

server {

        listen 80;
        server_name abc.com www.abc.com;
        location / {
                root /data/www/www;
                index index.html index.htm;
        }
 
        access_log    /var/log/nginx/access.log    main;

}

 

3.驗證是否正確

nginx -t

 

4.重啟生效(pid無變化)

nginx -s reload

 


免責聲明!

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



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