錯誤日誌配置與存取日誌配置
[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教程有興趣的朋友有所幫助。

phpsessionstrackuserdataacrossmultiplepagerequestsusingauniqueIdStoredInAcookie.here'showtomanageThemeffectionaly:1)startAsessionWithSessionWwithSession_start()和stordoredAtain $ _session.2)

在PHP中,遍歷會話數據可以通過以下步驟實現:1.使用session_start()啟動會話。 2.通過foreach循環遍歷$_SESSION數組中的所有鍵值對。 3.處理複雜數據結構時,使用is_array()或is_object()函數,並用print_r()輸出詳細信息。 4.優化遍歷時,可採用分頁處理,避免一次性處理大量數據。這將幫助你在實際項目中更有效地管理和使用PHP會話數據。

會話通過服務器端的狀態管理機制實現用戶認證。 1)會話創建並生成唯一ID,2)ID通過cookies傳遞,3)服務器存儲並通過ID訪問會話數據,4)實現用戶認證和狀態管理,提升應用安全性和用戶體驗。

Tostoreauser'snameinaPHPsession,startthesessionwithsession_start(),thenassignthenameto$_SESSION['username'].1)Usesession_start()toinitializethesession.2)Assigntheuser'snameto$_SESSION['username'].Thisallowsyoutoaccessthenameacrossmultiplepages,enhanc

PHPSession失效的原因包括配置錯誤、Cookie問題和Session過期。 1.配置錯誤:檢查並設置正確的session.save_path。 2.Cookie問題:確保Cookie設置正確。 3.Session過期:調整session.gc_maxlifetime值以延長會話時間。

在PHP中調試會話問題的方法包括:1.檢查會話是否正確啟動;2.驗證會話ID的傳遞;3.檢查會話數據的存儲和讀取;4.查看服務器配置。通過輸出會話ID和數據、查看會話文件內容等方法,可以有效診斷和解決會話相關的問題。

多次調用session_start()會導致警告信息和可能的數據覆蓋。 1)PHP會發出警告,提示session已啟動。 2)可能導致session數據意外覆蓋。 3)使用session_status()檢查session狀態,避免重複調用。

在PHP中配置會話生命週期可以通過設置session.gc_maxlifetime和session.cookie_lifetime來實現。 1)session.gc_maxlifetime控制服務器端會話數據的存活時間,2)session.cookie_lifetime控制客戶端cookie的生命週期,設置為0時cookie在瀏覽器關閉時過期。


熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

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

熱門文章

熱工具

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

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

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

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