location /logs { autoindex on; autoindex_exact_size on; autoindex_localtime on; alias /server/tomcat-data/logs; }
以上配置是 访问 host/logs能列出来 /server/tomcat-data/logs下的全部文件;nginx
autoindex 指的是容许不容许列出目录下文件,默认是不容许的。web
autindex_exact_size 限制文件大小tomcat
autoindex_localtime 显示出文件时间。bash
配置完成之后,我访问http://host/logs效果以下code
有时候咱们的服务是外网的,咱们不想谁都能访问的,这时候能够增长权限校验server
首先生成nginx的用户名和密码文件:io
htpasswd -c /usr/local/web/nginx/conf/passwd.db bktech New password: Re-type new password:
而后在刚才配置的location中增长校验需求便可class
location /logview { autoindex on; autoindex_exact_size on; autoindex_localtime on; alias /server/tomcat-data/logs; auth_basic "secret"; auth_basic_user_file /usr/local/web/nginx/conf/passwd.db; }
这样再访问/logview就须要输入咱们刚才配置的用户名和密码了配置