簡體   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