I just add a vhost in nginx.conf for autoindexing files like this:
server {
listen 80;
server_name res.rickyzhang.me;
root /home/wwwroot/default/res;
location = / {
autoindex on;
}
access_log /home/wwwlogs/access_res.log access;
}
i think this would work,but when i visit res.rickyzhang.me,it always give me a 400 response code,it means the request is invalid and can not be understood by the server,i am confused.Can anybody help me?Thanks.
I'm not sure but try adding a try_files
in it
location = / {
autoindex on;
try_files $uri $uri/;
}
Just tried on one of my servers:
# 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;
}
}
works as expected
i don't know whether it is appropriate to answer myself.
yesterday,i checked my nginx.conf carefully,i really counldn't find anything wrong.the 400 response code gives me some clues,so i just changed the hostname from res to dw,others have not changed,it worked!
it really amaze me,i guess maybe res is a reserved word in nginx,but i search on google,there isn't anything related to this.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.