nginx瀏覽器查看日志


1.安裝好nginx

如果啟動報錯nginx: [emerg] getpwnam("nginx") failed

說明沒有創建nginx用戶

useradd -s /sbin/nologin -M nginx                  #創建用戶解決

 

2.在nginx的配置文件里添加

# vim /usr/local/nginx/conf/nginx.conf

找到server標簽內容行添加

location /logs {
     alias /usr/local/nginx/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;
      #讓瀏覽器不保存臨時文件
     }

 

 

3.開啟在瀏覽器打開log文件,如果不開啟再點擊文件的時候就下載而不是打開

# vim /usr/local/nginx/conf/mime.types

types {
 text/html html htm shtml;
 text/log log;
 text/css css;
 text/xml xml;
 .............

 

4.然后重啟服務並在瀏覽器上查看效果

# /usr/local/nginx/sbin/nginx -s reload                   #重啟服務

如果之前沒有啟動     直接重啟會報錯

nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)

直接啟動就可以了

# /usr/local/nginx/sbin/nginx

在瀏覽器上查看效果    http://192.168.10.10/logs

 

對應網頁的路徑就是/usr/local/nginx/logs

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM