背景:
公司承接的客户业务是在共有云上,平时需要开发排查bug,但是又不想开发登录服务器,而且客户没有购买多余的服务器来部署elk来展示日志
此时,只需要增加一个nginx转发即可:
步骤如下:
[root@admin conf.d]# cat log.conf
server {
#listen 23652;
listen 80;
server_name localhost 172.21.25.11;
auth_basic "Please input password"; ##增加密码验证
auth_basic_user_file /etc/nginx/htpasswd;
location /logview {
#default_type text/html; ##或者修改http段的“default_type(全局修改,不建议)” ##具体的类型可以查看nginx的配置文件cat mime.types |grep "text"
有的时候网站使用特定的类型的时候也是这样自定,比如将字体或者字符集写到mime.types中,然后使用这个来改变显示的字符集或者字体(常用)
#default_type text/vnd.wap.wml;
default_type text/plain;
proxy_set_header Content-Type application/xhtml+xml; ##可加可不加
alias /opt/tomcat/log/newmedia/; ##日志路径
autoindex on;
autoindex_format html;
charset utf-8,gbk;
allow 211.111.1111.111; ##配置白名单
deny all;
}
}
这样在浏览器访问即可
#default_type text/html;
#default_type text/vnd.wap.wml;
default_type text/plain;
1、text/html的意思是将文件的content-type设置为text/html的形式,浏览器在获取到这种文件时会自动调用html的解析器对文件进行相应的处理。
2、text/plain的意思是将文件设置为纯文本的形式,浏览器在获取到这种文件时并不会对其进行处理。