錯誤log配置和存取log配置以及log記錄
錯誤日誌配置與存取日誌配置
[root@slave nginx]# vi /etc/nginx/nginx.conf
worker_processes 1;
error_log /var/log/nginx/error.log;
error_log /var/log/nginx/error.log;
;
事件{
worker_connections 1024;
}
http {
include mime.types; on;
keepalive_timeout 6 5;
log_format 指令'$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent" '“$http_user_agent”“$request_body” "$request_time"';
伺服器{
聽 80;
server_name www.wolf root html/www;
索引 index.html 索引.htm;
}
access_log /var/log/nginx/www.log comman;
}
伺服器{
wolf.com;
位置/ {
root html/bbs;
index index.html index.htm; server_name blog.wolf.com;
地點/ {
root html/blog;
index index.html index.htm; 伺服器{
聽 80;
server_name status.wolf.com;
location / {
stub_status on;
. }
}
設定完畢,測試如下
[root @ Slave nginx]#curl www.wolf.com
http://www.wolf.com
[root@slave nginx]# tail -f www.log
192.168.0.203 - - [11/ Jun /2016:16:26:52 +0800]“GET / HTTP/1.1”200 20“-”“curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.000 / 1.2.3 libidn/1.18 libssh2/1.4.2" "-" "0.000"
透過瀏覽器存取測試
================ == ===============================================
日誌對於統計排錯來說非常有利的。
本文總結了nginx日誌相關的設定如access_log、log_format、open_log_file_cache
、log_not_found、log_subrequest、rewrite_log、error_log。
nginx有一個非常靈活的日誌記錄模式。每個等級的配置可以有各自獨立的存取日誌。
日誌格式透過log_format指令來定義。
ngx_http_log_module是用來定義請求的日誌格式。
1. access_log指令
語法: access_log path [format [buffer=size [flush=time]]];
access_log path format gzip[=level] [buffer=size] [flush=time];
access_log syslog:server=address[,parameter=value] [format];
access_log off;
預設值: access_log logs/access.log combined;
設定段: http, server, lo. , if in location, limit_except
gzip壓縮等級。
buffer設定記憶體快取區大小。
flush保存在快取區中的最長時間。
不記錄日誌:access_log off;
使用預設combined格式記錄日誌:access_log logs/access.log 或access_log logs/access.log combined;
2、log_format指令
語法: log_format name string …;
預設值: log_format combined “…”;
配置段: http
name表示格式名稱,string表示等義的格式。
log_format有一個預設的不需設定的combined日誌格式,相當於apache的combined日誌格式,如下圖:
log_format combined '$remote_addr - $remote_user [$time_local]'
- $remote_user [$time_local]'
quest " $status $body_bytes_sent'
' "$http_referer" "$http_user_agent" ';
如果nginxIP.了。
$remote_addr取得反向代理的IP位址。反向代理伺服器在轉送請求的http頭資訊中,可以增加X-Forwarded-For訊息,
用來記錄 客戶端IP位址和客戶端請求的伺服器位址。
PS: 取得使用者真實IP 請參閱http://www.ttlsa.com/html/2235.html如下:
log_format porxy '$http_x_forwarded_for - $remote_user [$time_local]'
" $request" $status $body_bytes_sent '
' "$http_referer" "$http_user_agent" ';
請客戶端記錄編號$remote_user 記錄客戶端使用者名稱
$request 記錄請求的URL和HTTP協定
$status 記錄請求狀態
$body_bytes_sent 傳送給客戶端的位元組數,不包括回應頭的大小; 此變數與Apache模組mod_log_config裡的「%B」參數相容。
$bytes_sent 傳送給客戶端的總位元組數。
$connection 連接的序號。
$connection_requests 目前透過一個連線獲得的請求數量。
$msec 日誌寫入時間。單位為秒,精度是毫秒。
$pipe 如果請求是透過HTTP管線(pipelined)傳送,pipe值為“p”,否則為“.”。
$http_referer 記錄從哪個頁面連結存取過來的
$http_user_agent 記錄客戶端瀏覽器相關資訊
$request_length 請求的長度(包括請求行,請求頭和請求正文)。
$request_time 請求處理時間,單位為秒,精度毫秒; 從讀入客戶端的第一個位元組開始,直到把最後一個字元發送給客戶端後進行日誌寫入為止。
$time_iso8601 ISO8601標準格式下的本地時間。
$time_local 通用日誌格式下的本機時間。
[warning]傳送給客戶端的回應頭擁有「sent_http_」前綴。 如$sent_http_content_range。 [/warning]
實例如下:
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for '
log_format srcache_log '$remote_addr - $🎜> log_format srcache_log '$remote_addr - $ " '
'"$status" $body_bytes_sent $request_time $bytes_sent $request_length '
open_log_file_cache max= 1000 inactive=60s;
server {
server_name ~^(www.)?(.+)$;
access_log logs/$2-access.log main;
access_log logs/$2-access.log main;
access_log logs/$2-access.log main;
access_log logs/$2-access.log main;
-error.log;
location /srcache {
access_log logs/access-srcache.log srcache_log;
}
}
語法: open_log_file_cache max=N [inactive=time] [min_uses=N] [valid=time];
open_log_file_cache off;
預設值: open_log_file_cache off;
, server, server, server; location
對於每一條日誌記錄,都將是先開啟文件,再寫入日誌,然後關閉。可以使用open_log_file_cache來設定日誌檔案快取(預設是off),格式如下:
參數註解如下:
max:設定快取中的最大檔案描述符數量,如果快取被佔滿,採用LRU演算法將描述符關閉。
inactive:設定存活時間,預設是10s
min_uses:設定在inactive時間段內,日誌檔案最少使用多少次後,日誌檔案描述子記入快取中,預設是1次
valid :設定檢查頻率,預設60s
off:停用快取
實例如下:
open_log_file_cache max=1000 inactive=20s valid=1m min_uses=2;
4. log_not_found
設定段: http, server, location
是否在error_log中記錄不存在的錯誤。預設是。
5. log_subrequest指令
語法: log_subrequest on | off;
預設值: log_subrequest off;
設定段: http, server, location
是否在access_log中記錄子請求的存取日誌。預設不記錄。
6. rewrite_log指令
由ngx_http_rewrite_module模組提供的。用來記錄重寫日誌的。對於調試重寫規則建議開啟。 Nginx重寫規則指南
語法: rewrite_log on | off;
預設值: rewrite_log off;
設定段: http, server, location, if
啟用時將在error log中記錄notice等級的重寫日誌。
7. error_log指令
語法: error_log file | stderr | syslog:server=address[,parameter=value] [debug | info | notice | warn | error | crit | alert | emerg];
預設值: error_log logs/error.log error;
配置段: main, http, server, location
配置錯誤日誌。
本文總結了nginx日誌相關的設定如access_log、log_format、open_log_file_cache
、log_not_found、log_subrequest、rewrite_log、error_log。
nginx有一個非常靈活的日誌記錄模式。每個等級的配置可以有各自獨立的存取日誌。
日誌格式透過log_format指令來定義。
ngx_http_log_module是用來定義請求的日誌格式。
1. access_log指令
語法: access_log path [format [buffer=size [flush=time]]];
access_log path format gzip[=level] [buffer=size] [flush=time];
access_log syslog:server=address[,parameter=value] [format];
access_log off;
預設值: access_log logs/access.log combined;
設定段: http, server, lo. , if in location, limit_except
gzip壓縮等級。
buffer設定記憶體快取區大小。
flush保存在快取區中的最長時間。
不記錄日誌:access_log off;
使用預設combined格式記錄日誌:access_log logs/access.log 或access_log logs/access.log combined;
2、log_format指令
語法: log_format name string …;
預設值: log_format combined “…”;
配置段: http
name表示格式名稱,string表示等義的格式。
log_format有一個預設的不需設定的combined日誌格式,相當於apache的combined日誌格式,如下圖:
log_format combined '$remote_addr - $remote_user [$time_local]'
- $remote_user [$time_local]'
quest " $status $body_bytes_sent'
' "$http_referer" "$http_user_agent" ';
如果nginxIP.了。
$remote_addr取得反向代理的IP位址。反向代理伺服器在轉送請求的http頭資訊中,可以增加X-Forwarded-For訊息,
用來記錄 客戶端IP位址和客戶端請求的伺服器位址。
PS: 取得使用者真實IP 請參閱http://www.ttlsa.com/html/2235.html如下:
log_format porxy '$http_x_forwarded_for - $remote_user [$time_local]'
" $request" $status $body_bytes_sent '
' "$http_referer" "$http_user_agent" ';
請客戶端記錄編號$remote_user 記錄客戶端使用者名稱
$request 記錄請求的URL和HTTP協定
$status 記錄請求狀態
$body_bytes_sent 傳送給客戶端的位元組數,不包括回應頭的大小; 此變數與Apache模組mod_log_config裡的「%B」參數相容。
$bytes_sent 傳送給客戶端的總位元組數。
$connection 連接的序號。
$connection_requests 目前透過一個連線獲得的請求數量。
$msec 日誌寫入時間。單位為秒,精度是毫秒。
$pipe 如果請求是透過HTTP管線(pipelined)傳送,pipe值為“p”,否則為“.”。
$http_referer 記錄從哪個頁面連結存取過來的
$http_user_agent 記錄客戶端瀏覽器相關資訊
$request_length 請求的長度(包括請求行,請求頭和請求正文)。
$request_time 請求處理時間,單位為秒,精度毫秒; 從讀入客戶端的第一個位元組開始,直到把最後一個字元發送給客戶端後進行日誌寫入為止。
$time_iso8601 ISO8601標準格式下的本地時間。
$time_local 通用日誌格式下的本機時間。
[warning]傳送給客戶端的回應頭擁有「sent_http_」前綴。 如$sent_http_content_range。 [/warning]
實例如下:
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for '
log_format srcache_log '$remote_addr - $🎜> log_format srcache_log '$remote_addr - $ " '
'"$status" $body_bytes_sent $request_time $bytes_sent $request_length '
open_log_file_cache max= 1000 inactive=60s;
server {
server_name ~^(www.)?(.+)$;
access_log logs/$2-access.log main;
access_log logs/$2-access.log main;
access_log logs/$2-access.log main;
access_log logs/$2-access.log main;
-error.log;
location /srcache {
access_log logs/access-srcache.log srcache_log;
}
}
語法: open_log_file_cache max=N [inactive=time] [min_uses=N] [valid=time];
open_log_file_cache off;
預設值: open_log_file_cache off;
, server, server, server; location
對於每一條日誌記錄,都將是先開啟文件,再寫入日誌,然後關閉。可以使用open_log_file_cache來設定日誌檔案快取(預設是off),格式如下:
參數註解如下:
max:設定快取中的最大檔案描述符數量,如果快取被佔滿,採用LRU演算法將描述符關閉。
inactive:設定存活時間,預設是10s
min_uses:設定在inactive時間段內,日誌檔案最少使用多少次後,日誌檔案描述子記入快取中,預設是1次
valid :設定檢查頻率,預設60s
off:停用快取
實例如下:
open_log_file_cache max=1000 inactive=20s valid=1m min_uses=2;
4. log_not_found
設定段: http, server, location
是否在error_log中記錄不存在的錯誤。預設是。
5. log_subrequest指令
語法: log_subrequest on | off;
預設值: log_subrequest off;
設定段: http, server, location
是否在access_log中記錄子請求的存取日誌。預設不記錄。
6. rewrite_log指令
由ngx_http_rewrite_module模組提供的。用來記錄重寫日誌的。對於調試重寫規則建議開啟。 Nginx重寫規則指南
語法: rewrite_log on | off;
預設值: rewrite_log off;
設定段: http, server, location, if
啟用時將在error log中記錄notice等級的重寫日誌。
7. error_log指令
語法: error_log file | stderr | syslog:server=address[,parameter=value] [debug | info | notice | warn | error | crit | alert | emerg];
預設值: error_log logs/error.log error;
配置段: main, http, server, location
配置錯誤日誌。
以上就介紹了 錯誤log配置和存取log配置以及log記錄,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

SQL IF 語句用於有條件地執行 SQL 語句,語法為: IF (condition) THEN {語句} ELSE {語句} END IF;。條件可以是任何有效的 SQL 表達式,如果條件為真,執行 THEN 子句;如果條件為假,執行 ELSE 子句。 IF 語句可以嵌套,允許更複雜的條件檢查。

解決 Vue Axios 跨域問題的方法包括:服務器端配置 CORS 頭使用 Axios 代理使用 JSONP使用 WebSocket使用 CORS 插件

如何在 Apache 中配置 Zend?在 Apache Web 服務器中配置 Zend Framework 的步驟如下:安裝 Zend Framework 並解壓到 Web 服務器目錄中。創建 .htaccess 文件。創建 Zend 應用程序目錄並添加 index.php 文件。配置 Zend 應用程序(application.ini)。重新啟動 Apache Web 服務器。

多線程的好處在於能提升性能和資源利用率,尤其適用於處理大量數據或執行耗時操作。它允許同時執行多個任務,提高效率。然而,線程過多會導致性能下降,因此需要根據 CPU 核心數和任務特性謹慎選擇線程數。另外,多線程編程涉及死鎖和競態條件等挑戰,需要使用同步機制解決,需要具備紮實的並發編程知識,權衡利弊並謹慎使用。

無法以 root 身份登錄 MySQL 的原因主要在於權限問題、配置文件錯誤、密碼不符、socket 文件問題或防火牆攔截。解決方法包括:檢查配置文件中 bind-address 參數是否正確配置。查看 root 用戶權限是否被修改或刪除,並進行重置。驗證密碼是否準確無誤,包括大小寫和特殊字符。檢查 socket 文件權限設置和路徑。檢查防火牆是否阻止了 MySQL 服務器的連接。

本文介紹如何在Debian系統上有效監控Nginx服務器的SSL性能。我們將使用NginxExporter將Nginx狀態數據導出到Prometheus,再通過Grafana進行可視化展示。第一步:配置Nginx首先,我們需要在Nginx配置文件中啟用stub_status模塊來獲取Nginx的狀態信息。在你的Nginx配置文件(通常位於/etc/nginx/nginx.conf或其包含文件中)中添加以下代碼段:location/nginx_status{stub_status

PHPMyAdmin安全防禦策略的關鍵在於:1. 使用最新版PHPMyAdmin及定期更新PHP和MySQL;2. 嚴格控制訪問權限,使用.htaccess或Web服務器訪問控制;3. 啟用強密碼和雙因素認證;4. 定期備份數據庫;5. 仔細檢查配置文件,避免暴露敏感信息;6. 使用Web應用防火牆(WAF);7. 進行安全審計。 這些措施能夠有效降低PHPMyAdmin因配置不當、版本過舊或環境安全隱患導致的安全風險,保障數據庫安全。

有效監控和防禦惡意網站訪問對於Debian系統的Apache服務器至關重要。 Apache訪問日誌是識別此類威脅的關鍵信息來源。本文將指導您如何分析日誌並採取防禦措施。識別惡意訪問行為Debian系統的Apache訪問日誌通常位於/var/log/apache2/access.log。您可以通過多種方法分析日誌:日誌文件位置確認:首先,請確認您的Apache訪問日誌的準確位置,它可能因係統配置而略有不同。命令行工具分析:使用grep命令搜索特定模式,例如grep"404"
