Nginx设置访问服务器某个目录

最近实时的项目有个需求,就是要查看集群中各个节点下面跑的项目的Log。于是想到了用Nginx将log目录暴露出来集成到现有的监控平台中去。
nginx的安装配置在前面的博客中有提到过,这里记录下如何配置访问log目录。

1 首先,设置权限

配置需要访问的log目录有权限

chmod -R /.../...

在nginx.conf文件中,添加或覆盖下面一行

user  root;

2 配置server节点

server {
        listen       64001;
        server_name  beta3.hadoop.feidai.com;

        charset utf-8;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
            autoindex on;
        }

        location /feidai-kafka-kudu/bin/slog {
            root    /root;
            autoindex on;
        }

        location /feidai-canal-kafka/bin/slog {
            root    /root;
            autoindex on;
        }
        ......

其中添加了两个location节点,配置autoindex on;使其能展示目录。
在location节点里面配置alas会把指定路径当作文件路径,
而配置root会把指定路径拼接到文件路径后,再进行访问。
这里使用root配置。
访问实例:http://beta3.hadoop.feidai.com:64001/feidai-kafka-kudu/bin/slog/
整合到监控平台的效果如下图
这里写图片描述

猜你喜欢

转载自blog.csdn.net/weixin_35852328/article/details/81181353