一、在nginx配置文件的server标签内加入以下标签和内容
location /logs {alias /data/nginx/logs;#nginx日志目录autoindex on;#打开目录浏览功能autoindex_exact_size off;#默认为on,显示出文件的确切大小,单位是bytes#显示出文件的大概大小,单位是kb或者mb或者gbautoindex_localtime on;#默认为off,显示的文件时间为gmt时间。#改为on后,显示的文件时间为文件的服务器时间add_header cache-control no-store;#让浏览器不保存临时文件
}
二、开启在浏览器打开log文件,如果不开启再点击文件的时候就下载而不是打开
vim mime.types
types {text/html html htm shtml;text/log log;text/css css;text/xml xml;.............
三、检测语法,然后让nginx配置生效,在浏览器查看
./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
./nginx -s reload
打开浏览器输入域名或者ip,后面加上logs,然后点击文件就可以打开了,如果日志随随便便就可以被别人查看是不是很不安全,所以我们要在加一