一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術(shù)及軟件下載分享
分類導航

云服務器|WEB服務器|FTP服務器|郵件服務器|虛擬主機|服務器安全|DNS服務器|服務器知識|Nginx|IIS|Tomcat|

服務器之家 - 服務器技術(shù) - Nginx - Nginx實現(xiàn)瀏覽器可實時查看訪問日志的步驟詳解

Nginx實現(xiàn)瀏覽器可實時查看訪問日志的步驟詳解

2019-11-14 16:56daisy Nginx

我們經(jīng)常需要在頁面上實時查看nginx的日志輸出,并且能在頁面上顯示,那么下面小編就給大家說下怎么在瀏覽器上實時動態(tài)的查看nginx的訪問日志,有需要的朋友們可以參考借鑒。

一、首先查看nginx版本,我使用的是1.9.7的版本,安裝目錄在/application/nginx-1.9.7

?
1
2
3
4
[root@AnSheng ~]# /application/nginx-1.9.7/sbin/nginx -V
nginx version: nginx/1.9.7
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)
configure arguments: --prefix=/application/nginx-1.9.7 --user=nginx --group=nginx --with-http_stub_status_module

二、檢查語法并啟動nginx

?
1
2
3
4
[root@AnSheng ~]# /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
[root@AnSheng ~]# /application/nginx-1.9.7/sbin/nginx

三、把nginx配置文件內(nèi)多余的注視行和空行刪掉

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[root@AnSheng ~]# cd /application/nginx-1.9.7/conf/
[root@AnSheng conf]# egrep -v "#|^$" nginx.conf.default
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;
  }
 }
}
[root@AnSheng conf]# egrep -v "#|^$" nginx.conf.default nginx.conf

四、在nginx配置文件的server標簽內(nèi)加入以下標簽和內(nèi)容

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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文件,如果不開啟再點擊文件的時候就下載而不是打開

?
1
2
3
4
5
6
7
[root@AnSheng conf]# vim mime.types
types {
 text/html html htm shtml;
 text/log log;
 text/css css;
 text/xml xml;
 .............

六、檢測語法,然后讓nginx配置生效,在瀏覽器查看

?
1
2
3
4
[root@AnSheng conf]# /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
[root@AnSheng conf]# /application/nginx-1.9.7/sbin/nginx -s reload

打開瀏覽器輸入域名或者IP,后面加上logs,然后點擊文件就可以打開了,如果日志隨隨便便就可以被別人查看是不是很不安全,所以我們要在加一層nginx用戶認證。

Nginx實現(xiàn)瀏覽器可實時查看訪問日志的步驟詳解

Nginx實現(xiàn)瀏覽器可實時查看訪問日志的步驟詳解

七、安裝httpd-tools,用于帳號密碼生成

?
1
[root@AnSheng ~]# yum -y install httpd-tools

八、創(chuàng)建認證的賬號

?
1
2
3
4
5
[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加入下面的內(nèi)容

?
1
2
3
4
5
6
7
8
9
10
11
12
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實現(xiàn)瀏覽器可實時查看訪問日志的步驟詳解

十一、總結(jié)

以上就是利用Nginx實現(xiàn)瀏覽器可實時查看訪問日志的全部步驟,希望對大家的學習或者工作有所幫助,如果有疑問大家可以留言交流。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 男人天堂2023| 国产一区二区三区免费在线视频 | 国产成人亚洲精品一区二区在线看 | 婷婷久久综合九色综合九七 | 亚洲男男video | 暗卫调教女主肉高h | 日韩免费视频播播 | 天码毛片一区二区三区入口 | 99精品网 | 国产精品一区二区久久不卡 | 男人亚洲天堂 | 四虎影视884aa·com | 亚洲 色 欧美 爱 视频 日韩 | 涩情主播在线翻车 | 欧美成人aa久久狼窝动画 | 日韩永久在线观看免费视频 | 奇米视频7777| 高清毛片aaaaaaaaa片 | 日本三级成人中文字幕乱码 | 湿好紧太硬了我太爽了 | 范冰冰上面好大下面好紧 | 朝鲜女人free性hu | 三体动漫在线观看免费完整版2022 | xxx88视频在线观看 | 亚洲国产一区 | 999任你躁在线精品免费不卡 | 精品一久久香蕉国产线看观 | 高h禁伦奶水女 | 非洲黑人又大粗gay 非洲黑人bbwbbwbbw | 啊啊啊好爽在线观看 | 国内交换一区二区三区 | 精品亚洲综合久久中文字幕 | 日本在线亚州精品视频在线 | 4455在线 | 亚洲免费国产 | juliaann大战七个黑人 | 亚洲成综合 | 日韩毛片在线 | 关晓彤一级做a爰片性色毛片 | 菠萝视频在线完整版 | 亚洲午夜精品久久久久久成年 |