Occasionally I need some plain browsable directories on my site. I do achieve this with the following config:
... root /var/www/example.com/file_dump; autoindex off; ... location / { try_files $uri /error.html @django; } location @django { ... } location ~ ^/test/.+/? { autoindex on; } So if I would create a directory /var/www/example.com/file_dump/test/something, I would get the list of files at the address example.com/test/something.
I have tried to be smarter than this with the following config:
location / { if (!-d test/$uri) { autoindex on; } try_files $uri /error.html @django; } But I've met the following error:
nginx: [emerg] "autoindex" directive is not allowed here...
Why Nginx does not allow autoindex within the conditional statements? Can I enable autoindex dynamically by the other means?
autoindexdirective within theifblock in location because if in location is not listed as allowed contexts for theautoindexdirective (unlike some others)"? nginx conditional statements is a very special thing and should be used with caution. The best practice is to avoid theifwhenever possible.autoindex dynamically by the other means, thus without theif. @MichaelHampton Thank you, I'm aware of the ifisevil.