nginx檢視實時日誌並設簡單的訪問驗證
關於檢視實時日誌的思路
1.我一般是自畫頁面,寫後端api
2.nginx可以實現簡單的效果
配置
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
配置檢視目錄
location /logs {
alias /application/nginx-1.9.7/logs;
#Nginx日誌目錄
autoindex on;
#開啟目錄瀏覽功能
autoindex_exact_size off;
#預設為on,顯示出檔案的確切大小,單位是bytes
#顯示出檔案的大概大小,單位是kB或者MB或者GB
autoindex_localtime on;
#預設為off,顯示的檔案時間為GMT時間。
#改為on後,顯示的檔案時間為檔案的伺服器時間
add_header Cache-Control no-store;
#讓瀏覽器不儲存臨時檔案
}
開啟在瀏覽器開啟log檔案,如果不開啟再點選檔案的時候就下載而不是開啟
# vim mime.types
types {
text/html html htm shtml;
text/log log;
text/css css;
text/xml xml;
.............
檢測語法,然後讓nginx配置生效,在瀏覽器檢視
# /application/nginx-1.9.7/sbin/nginx -t
nginx: the configuration file /application/nginx-1.9.7/conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.9.7/conf/nginx.conf test is successful
# /application/nginx-1.9.7/sbin/nginx -s reload
開啟瀏覽器輸入域名或者IP,後面加上logs,然後點選檔案就可以開啟了,如果日誌隨隨便便就可以被別人檢視是不是很不安全,所以我們要在加一層nginx使用者認證。

nginx-web-01

nginx-web-02
安裝httpd-tools,用於帳號密碼生成
[root@AnSheng ~]# yum -y install httpd-tools
建立認證的賬號
[root@AnSheng ~]# htpasswd -c /application/nginx-1.9.7/conf/loguser loguser
New password:
Re-type new password:
Adding password for user loguser
#密碼需要輸入兩次
編輯nginx配置檔案,在logs的location加入下面的內容
location /logs {
......
alias PATH;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
add_header Cache-Control no-store;
auth_basic "Restricted";
#Nginx認證
auth_basic_user_file /application/nginx-1.9.7/conf/loguser;
#認證賬號密碼儲存的檔案
}
然後再開啟的時候就會提示輸入賬號和密碼,登陸之後才可以檢視。

nginx-web-03
相關文章
- Nginx訪問日誌詳解——各個部分含義——非常簡單Nginx
- Nginx入門教程(五)---訪問日誌簡單分析,統計PV、UV等資料。Nginx
- awk統計訪問nginx日誌次數Nginx
- Linux 中實時檢視日誌的3種方法Linux
- Linux下使用GoAccess監控Nginx訪問日誌LinuxGoNginx
- 如何使用Journalctl檢視並操作Systemd日誌
- Web實時日誌輸出檢視管理系統Web
- 處理nginx訪問日誌,篩選時間大於1秒的請求Nginx
- Django websocket之web端實時檢視日誌實踐案例DjangoWeb
- nginx高階訪客日誌切割Nginx
- eclipse設定檢視GC日誌和如何理解GC日誌EclipseGC
- Linux 檢視日誌Linux
- alertmanager: 檢視日誌
- 檢視系統的日誌
- nginx配置web訪問以及檢視目錄檔案NginxWeb
- FeignClient配置日誌訪問client
- Nginx日誌格式設定Nginx
- Hyperf日誌檢視元件元件
- Logminer如何檢視日誌
- mysqld啟動失敗時日誌檢視命令MySql
- SVN解決不能檢視最近提交日誌的問題
- 如何定時切割nginx日誌?Nginx
- 檢視日誌的幾種形式
- Nginx統計訪問IP並排序Nginx排序
- Tomcat訪問日誌淺析Tomcat
- 如何在ABAP Netweaver和CloudFoundry裡記錄並檢視日誌Cloud
- 【Nginx】如何格式化日誌並推送到遠端伺服器?看完原來很簡單!!Nginx伺服器
- 安全開發Java:日誌注入,並沒那麼簡單Java
- 解鎖Nginx日誌的寶藏:GoAccess——你的實時、互動式Web日誌分析神器!NginxGoWeb
- docker檢視容器日誌命令Docker
- windows_weblogic日誌檢視WindowsWeb
- Monaco Editor 實現一個日誌檢視器
- Linux 檢視日誌的命令彙總Linux
- CentOS 7.0下nginx實現每天定時分割日誌CentOSNginx
- 簡單的C#日誌類C#
- 使用Fluentd + Elasticsearch收集訪問日誌Elasticsearch
- go fiber: 增加訪問日誌accesslogGo
- Python實現簡單驗證碼的轉文字Python
- jquery 實現滑動條的簡單驗證jQuery