Nginx – How to… DirectoryIndex to a folder

apache-2.2directoryindexnginxrewrite

I want to set a initial page inside a folder, besides the common index.htm

I want to change index.htm to /folder/file.htm

Is it possible using nginx?

In my Apache server all I have to do is config the htaccess file, putting this:
DirectoryIndex /folder/file.htm

PS: I tried to do that with RegEx, but I really preffer with DirectoryIndex

Thanks a lot in advance!!!

Best Answer

Nginx has a directive, index, that is equivalent to Apache's DirectoryIndex. As per the documentation:

index
Syntax: index file ...
Default: index.html
Context: http, server, location

Sets the default file to serve if a directory is requested by the client. Multiple files can be specified. If the first file isn't found, the second will be used and so on. If the last entry begins with a /, and none of the earlier files are found, nginx will perform an internal redirect to this uri.

e.g. index index.html index.php /index.php;

As indicated from the above, you can specify multiple files, each of which will be tried in sequence, and can also specify an full path if the file you wish to use is not under the current directory.

Related Topic