如何配置Nginx启用“文件浏览器"模式? [英] How to configure nginx to enable kinda 'file browser' mode?

查看:69
本文介绍了如何配置Nginx启用“文件浏览器"模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在输入URL http://test.com/test/之前,我曾经看到过这种情况,而不是给我一个html页面,它为我提供了一个类似于文件浏览器"的界面,可以浏览给定位置中的所有文件.

Once I've seen this before when I type a URL http://test.com/test/, instead of give me a html page, it gives me a 'file browser' like interface to browse all the files in the given location.

我认为可能是可以在位置上下文中启用的nginx模块.

I think it maybe a nginx module that could be enable in the location context.

nginx.conf文件:

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  122.97.248.252;
                location /test {
                        root /home/yozloy/html/;
                        autoindex on;
                }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

更新error.log

2012/05/19 20:48:33 [错误] 20357#0:* 72 open()"/home/yozloy/html/test"失败(2:无此类文件或目录),客户端:125.43. 236.33,服务器:122.97.248.252,请求:"GET/test HTTP/1.1",主机:"unicom2.markson.hk

2012/05/19 20:48:33 [error] 20357#0: *72 open() "/home/yozloy/html/test" failed (2: No such file or directory), client: 125.43.236.33, server: 122.97.248.252, request: "GET /test HTTP/1.1", host: "unicom2.markson.hk

我必须误解位置/test的意思,我以为是指我键入 http://example.com/test时的意思,那么它将访问/home/yozloy/html/

I must misunderstand the location /test mean, I thought it meant when I type http://example.com/test, then it would access the root dictionary which is /home/yozloy/html/

推荐答案

您应尝试使用HttpAutoindexModule.

You should try HttpAutoindexModule.

将自动索引选项设置为on.默认情况下处于关闭状态.

Set autoindex option to on. It is off by default.

您的示例配置应该可以

location /{ 
   root /home/yozloy/html/; 
   index index.html; 
   autoindex on;
}

没有自动索引选项,对于没有index.html文件的目录,对于以/结尾的请求,您应该会收到错误403.使用此选项,您应该会得到一个简单的清单:

Without autoindex option you should be getting Error 403 for requests that end with / on directories that do not have an index.html file. With this option you should be getting a simple listing:

<html>
<head><title>Index of /</title></head>
<body bgcolor="white">
<h1>Index of /test/</h1><hr><pre><a href="../">../</a>
<a href="test.txt">test.txt</a>                 19-May-2012 10:43            0
</pre><hr></body>
</html>

:更新了清单,以删除要测试的所有引用

Updated the listing to delete any references to test

这篇关于如何配置Nginx启用“文件浏览器"模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆