Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to set up nginx so that a certain url produces the directory index of a certain directory on my server. Currently this is what my default.conf looks like.

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;

    location /files/ {
        root        /home/myfiles/Downloads;
        autoindex   on;

However when I try to go to or I get a 403 Forbidden error.

Looking into the error log I saw

2012/01/08 16:23:18 [error] 17619#0: *1 "/home/myfiles/Downloads/files/index.html" is forbidden (13: Permission denied), client: some.ip.addr.ess, server: _, request: "GET /files/ HTTP/1.1",

I don't want it to search for files/index.html, I just want the directory index of Downloads. What do I need to change to make things work this way?

share|improve this question
up vote 4 down vote accepted

Check whether Nginx has execute permissions for the all the directories in the parent directory tree. In your case, Nginx should have execute permissions for /, /home, /home/myfiles, /home/myfiles/Downloads or else Nginx cannot chdir to those directories.

share|improve this answer
Thanks, I didn't know it needed execute permissions for the entire heirachy. I had only set the execute permissions for the Downloads directory. – Varun Madiath Jan 9 '12 at 10:14

In this case you need to use the alias directive instead of root.

When using root, a request to will look in the local directory /home/myfiles/Downloads/files/ for an index file, and if not found will automatically generate a directory listing (since you have specified the autoindex option). Note how nginx appends /files/ to the root directory you specified.

Since for your case you want /files/ to be a synonym for your download directory, you need to use alias /home/myfiles/Downloads/ in the location block. Then, any request to will be translated to the directory /home/myfiles/Downloads/ (e.g. will become /home/myfiles/Downloads/bigfile.gz). Note that the trailing / on the alias is necessary.

See the documentation for more details on alias.

share|improve this answer
helped a lot! thanks – Totty.js Oct 10 '12 at 14:30

According to the nginx documentation:
"The request only reaches the ngx_http_autoindex_module when the ngx_http_index_module did not find an index file."

If an index is not defined for a location, it defaults to these values: index index.html.

Remove the index.html from /home/myfiles/Downloads/files/ and it should display the files in a directory listing

share|improve this answer
No index.html file exists in that location. Yet I still get the error. The files directory is owned by the group nginx, and has 750 permissions. All files in the director have the same owner and permissions are the files directory. – Varun Madiath Jan 9 '12 at 8:19

hi i also have autoindex error. BTW: I install nginx use a third party repo.

First i just check autoindex

/opt/tengine/sbin/nginx -V 2>&1 | grep auto

[root@sec002 tengine]# /opt/tengine/sbin/nginx -V 2>&1 | grep auto
            ngx_http_autoindex_module (static)

My server config

server {
    listen 8082;
    root /tmp;
    autoindex on;
    location / {
        root /tmp/php/;
        autoindex on;
        autoindex_exact_size off;
        autoindex_localtime on;

i browser ,error below:

2016/01/07 16:09:26 [error] 4205#0: *1 "/tmp/php/index.html" is not found (2: No such file or directory), client:, server:, request: "GET / HTTP/1.1", host: ""

I ensure execute permission and nginx user are right it's werid

Finally, i give up and rebuild nginx by tar package with default. then it's worked

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.