Nginx怎么實(shí)現(xiàn)瀏覽器可實(shí)時(shí)查看訪問(wèn)日志

這篇文章主要講解了“Nginx怎么實(shí)現(xiàn)瀏覽器可實(shí)時(shí)查看訪問(wèn)日志”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“Nginx怎么實(shí)現(xiàn)瀏覽器可實(shí)時(shí)查看訪問(wèn)日志”吧!

成都創(chuàng)新互聯(lián)公司專(zhuān)業(yè)為企業(yè)提供永康網(wǎng)站建設(shè)、永康做網(wǎng)站、永康網(wǎng)站設(shè)計(jì)、永康網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、永康企業(yè)網(wǎng)站模板建站服務(wù),10多年永康做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。

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

[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

二、檢查語(yǔ)法并啟動(dòng)nginx

[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)多余的注視行和空行刪掉

[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標(biāo)簽內(nèi)加入以下標(biāo)簽和內(nèi)容

location /logs {
 alias /application/nginx-1.9.7/logs;
 #nginx日志目錄

 autoindex on;
 #打開(kāi)目錄瀏覽功能

 autoindex_exact_size off;
 #默認(rèn)為on,顯示出文件的確切大小,單位是bytes
 #顯示出文件的大概大小,單位是kb或者mb或者gb

 autoindex_localtime on;
 #默認(rèn)為off,顯示的文件時(shí)間為gmt時(shí)間。
 #改為on后,顯示的文件時(shí)間為文件的服務(wù)器時(shí)間

 add_header cache-control no-store;
 #讓瀏覽器不保存臨時(shí)文件
}

五、開(kāi)啟在瀏覽器打開(kāi)log文件,如果不開(kāi)啟再點(diǎn)擊文件的時(shí)候就下載而不是打開(kāi)

[root@ansheng conf]# vim mime.types
types {
 text/html html htm shtml;
 text/log log;
 text/css css;
 text/xml xml;
 .............

六、檢測(cè)語(yǔ)法,然后讓nginx配置生效,在瀏覽器查看

[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

打開(kāi)瀏覽器輸入域名或者ip,后面加上logs,然后點(diǎn)擊文件就可以打開(kāi)了,如果日志隨隨便便就可以被別人查看是不是很不安全,所以我們要在加一層nginx用戶(hù)認(rèn)證。

Nginx怎么實(shí)現(xiàn)瀏覽器可實(shí)時(shí)查看訪問(wèn)日志

Nginx怎么實(shí)現(xiàn)瀏覽器可實(shí)時(shí)查看訪問(wèn)日志

七、安裝httpd-tools,用于帳號(hào)密碼生成

[root@ansheng ~]# yum -y install httpd-tools

八、創(chuàng)建認(rèn)證的賬號(hào)

[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)容

location /logs {
 ......
 alias path;
 autoindex on;
 autoindex_exact_size off;
 autoindex_localtime on;
 add_header cache-control no-store;
 auth_basic "restricted";
 #nginx認(rèn)證
 auth_basic_user_file /application/nginx-1.9.7/conf/loguser;
 #認(rèn)證賬號(hào)密碼保存的文件
}

十、然后再打開(kāi)的時(shí)候就會(huì)提示輸入賬號(hào)和密碼,登陸之后才可以查看。

Nginx怎么實(shí)現(xiàn)瀏覽器可實(shí)時(shí)查看訪問(wèn)日志

感謝各位的閱讀,以上就是“Nginx怎么實(shí)現(xiàn)瀏覽器可實(shí)時(shí)查看訪問(wèn)日志”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)Nginx怎么實(shí)現(xiàn)瀏覽器可實(shí)時(shí)查看訪問(wèn)日志這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

網(wǎng)站名稱(chēng):Nginx怎么實(shí)現(xiàn)瀏覽器可實(shí)時(shí)查看訪問(wèn)日志
分享地址:http://muchs.cn/article16/iioedg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作面包屑導(dǎo)航、網(wǎng)站排名、自適應(yīng)網(wǎng)站、品牌網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)