日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Nginx >内容正文

Nginx

Nginx访问日志(access_log)配置

發布時間:2024/3/24 Nginx 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Nginx访问日志(access_log)配置 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Nginx訪問日志主要有兩個參數控制

log_format #用來定義記錄日志的格式(可以定義多種日志格式,取不同名字即可)

access_log #用來指定日至文件的路徑及使用的何種日志格式記錄日志

lof_format的默認值:

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

access_log的默認值:

#access_log logs/access.log main;

log_format語法格式及參數語法說明如下:

log_format <NAME> <Strin---g>;關鍵字 格式標簽 日志格式關鍵字:其中關鍵字error_log不能改變格式標簽:格式標簽是給一套日志格式設置一個獨特的名字日志格式:給日志設置格式log_format格式變量:$remote_addr #記錄訪問網站的客戶端地址$remote_user #遠程客戶端用戶名$time_local #記錄訪問時間與時區$request #用戶的http請求起始行信息$status #http狀態碼,記錄請求返回的狀態碼,例如:200、301、404等$body_bytes_sent #服務器發送給客戶端的響應body字節數$http_referer #記錄此次請求是從哪個連接訪問過來的,可以根據該參數進行防盜鏈設置。$http_user_agent #記錄客戶端訪問信息,例如:瀏覽器、手機客戶端等$http_x_forwarded_for #當前端有代理服務器時,設置web節點記錄客戶端地址的配置,此參數生效的前提是代理服務器也要進行相關的x_forwarded_for設置

access_log語法格式及參數語法說明如下:

access_log <FILE> <NAME>;關鍵字 日志文件 格式標簽關鍵字:其中關鍵字error_log不能改變日志文件:可以指定任意存放日志的目錄格式標簽:給日志文件套用指定的日志格式其他語法:access_log off; #關閉access_log,即不記錄訪問日志access_log path [format [buffer=size [flush=time]] [if=condition]];access_log path format gzip[=level] [buffer=size] [flush=time] [if=condition];access_log syslog:server=address[,parameter=value] [format [if=condition]];說明:buffer=size #為存放訪問日志的緩沖區大小flush=time #為緩沖區的日志刷到磁盤的時間gzip[=level] #表示壓縮級別[if = condition] #表示其他條件

一般場景這些參數都無需配置,極端優化才有可能會考慮這些參數。

lof_format參數的標簽段位置:

http

access_log參數的標簽段位置:

http, server, location, if in location, limit_except

參考資料:http://nginx.org/en/docs/http/ngx_http_log_module.html

Nginx配置訪問日志過程:

(1)創建log_format語句

worker_processes 1; error_log logs/error.log error; events {worker_connections 1024; } http {include status.conf;include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65;log_format main '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log logs/access.log main;server {listen 80;server_name localhost;rewrite ^/.* http://www.wl.com permanent;}include vhost/*.conf; }

(2)插入access_log語句

server {access_log /data/log/www;listen 80;server_name abc.com www.wl.com;location / {root /data/www/www;index index.html index.htm;}error_log logs/error_www.wl.com.log error;access_log logs/access_www.wl.com.log main;#新增內容↑}

(3)重啟服務

nginx -t nginx -s reload

轉載于:https://www.cnblogs.com/xuyuQAQ/p/8728773.html

總結

以上是生活随笔為你收集整理的Nginx访问日志(access_log)配置的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。