2

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!!!

Gus
  • 21
  • 1
  • 2
  • The equivalent directive for nginx is [`index`](http://wiki.nginx.org/HttpIndexModule#index). You can specify multiple files, and/or an absolute path that will result in an internal redirect. – cyberx86 Jun 28 '12 at 05:24
  • @cyberx86 Why not post that as an answer? – mgorven Jun 28 '12 at 05:54

1 Answers1

3

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.

cyberx86
  • 20,620
  • 1
  • 60
  • 80
  • Thanks a lot cyberx86, I will try this and let you know if worked. – Gus Jun 28 '12 at 12:52
  • I have a special php file that lists directories and wanted all directories without their own index files to be rewritten to that file - using an absolute path with this directive as the last parameter did just that. Works fine, thanks! – Strayer Dec 10 '12 at 11:41