繁体   English   中英

如何设置虚拟主机以使用Nginx自动索引文件

[英]How to set up a vhost to autoindex the files using nginx

我只是在nginx.conf中添加了一个虚拟主机,用于自动索引文件,如下所示:

server {
    listen       80;
    server_name res.rickyzhang.me;
    root  /home/wwwroot/default/res;
    location = / {
        autoindex      on;
    }
    access_log  /home/wwwlogs/access_res.log  access;
}

我认为这行得通,但是当我访问res.rickyzhang.me时,它总是给我400响应代码,这意味着请求无效且服务器无法理解,我很困惑。有人可以帮助我吗?谢谢。

我不确定,但尝试在其中添加try_files

location = / {
    autoindex      on;
    try_files $uri $uri/;
}

刚在我的一台服务器上尝试过:

# nginx -V
nginx version: nginx/1.4.1
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC)

server {
    server_name  some_hostname;

    location = / {
        root   html;
        autoindex on;
#http://wiki.nginx.org/HttpAutoindexModule
#The request only reaches the ngx_http_autoindex_module when 
#the ngx_http_index_module did not find an index file.
        index  should_not_exist;
    }
}

按预期工作

我不知道回答自己是否合适。

昨天,我仔细检查了我的nginx.conf,我真的没发现任何问题。400响应代码为我提供了一些线索,所以我只是将主机名从res更改为dw,其他都没有更改,它起作用了!

这真的让我感到惊讶,我想res可能是nginx中的保留字,但是我在Google上搜索,与此没有任何关系。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM