1.修改nginx.conf
location /logs {
alias /home/data/logs; #日志文件目錄路徑
autoindex on;
autoindex_exact_size off;
autoindex_localtime on; #默認為off,顯示的文件時間為GMT時間。改為on后,顯示的文件時間為文件的服務器時間
add_header Cache-Control no-store; #讓瀏覽器不保存臨時文件
allow 114.242.192.133; #出于安全考慮可以設置ip白名單,或者使用下面的密碼訪問策略
deny all;
}
2.修改 mime.type
在其中新增
text/log log; 以log為擴展名的文件,如果目錄下有其它類型的日志文件需要查看,可以進行增加,例如: text/log json;
3.密碼訪問策略
1、yum -y install httpd-tools
2、htpasswd -c /usr/local/nginx/conf/loguser wjoyxt
3、在以上修改的conf配置文件中增加兩行:
auth_basic "Restricted";
auth_basic_user_file /usr/local/nginx/conf/loguser; #認證賬號密碼保存的文件
4.重啟nginx
nginx -s reload