這篇文章主要講解了“Nginx怎么實(shí)現(xiàn)瀏覽器可實(shí)時查看訪問日志”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“Nginx怎么實(shí)現(xiàn)瀏覽器可實(shí)時查看訪問日志”吧!
成都創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供永康網(wǎng)站建設(shè)、永康做網(wǎng)站、永康網(wǎng)站設(shè)計(jì)、永康網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、永康企業(yè)網(wǎng)站模板建站服務(wù),10多年永康做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價值的思路和整體網(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
二、檢查語法并啟動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; #打開目錄瀏覽功能 autoindex_exact_size off; #默認(rèn)為on,顯示出文件的確切大小,單位是bytes #顯示出文件的大概大小,單位是kb或者mb或者gb autoindex_localtime on; #默認(rèn)為off,顯示的文件時間為gmt時間。 #改為on后,顯示的文件時間為文件的服務(wù)器時間 add_header cache-control no-store; #讓瀏覽器不保存臨時文件 }
五、開啟在瀏覽器打開log文件,如果不開啟再點(diǎn)擊文件的時候就下載而不是打開
[root@ansheng conf]# vim mime.types types { text/html html htm shtml; text/log log; text/css css; text/xml xml; .............
六、檢測語法,然后讓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
打開瀏覽器輸入域名或者ip,后面加上logs,然后點(diǎn)擊文件就可以打開了,如果日志隨隨便便就可以被別人查看是不是很不安全,所以我們要在加一層nginx用戶認(rèn)證。
七、安裝httpd-tools,用于帳號密碼生成
[root@ansheng ~]# yum -y install httpd-tools
八、創(chuàng)建認(rèn)證的賬號
[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)證賬號密碼保存的文件 }
十、然后再打開的時候就會提示輸入賬號和密碼,登陸之后才可以查看。
感謝各位的閱讀,以上就是“Nginx怎么實(shí)現(xiàn)瀏覽器可實(shí)時查看訪問日志”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對Nginx怎么實(shí)現(xiàn)瀏覽器可實(shí)時查看訪問日志這一問題有了更深刻的體會,具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識點(diǎn)的文章,歡迎關(guān)注!
網(wǎng)站名稱:Nginx怎么實(shí)現(xiàn)瀏覽器可實(shí)時查看訪問日志
分享地址:http://bm7419.com/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)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容