How to parse index.html before index.php


#1

I host WP sites so they are all happy with:

location / {  
    try_files $uri $uri/ /index.php?$args;  
}   

BUT if there is a index.html and no index.php I get a 404 error. Is there a way to change the above code to first look for index.html and only if not found look for index.php?


#2

Look for a line like index index.php

It might be in main nginx.conf. If not found simply add a line like:

index index.html index.php OR index index.php index.html depending on priority you want for them inside server { ..} block or nginx.conf block.

For more details: http://wiki.nginx.org/HttpIndexModule#index


#3

Sorry for not being more specific:

I use ISPCFG3 and initially the template for nginx vhosts contains this line:

       index index.html index.htm index.php index.cgi index.pl index.xhtml;  

BUT as soon as I add this directive to a vhost the site stops looking for index.html files.

location / {  
try_files $uri $uri/ /index.php?$args;  

}

So I assumed they were conflicting and I would have to add index.html somehow to the try_files directive.

Any other pointers for me?


#4

You can add index line outside location block.

It should work there as well.

Apart from this, if ISPconfig is doing anything unexpected behind the scene, then I won't be able to help.


#5

Hm, might have to post in the ISPCFG forums. As I said this line is inside the server location, index index.html index.htm index.php index.cgi index.pl index.xhtml;

but as soon as I add the try_files directive, which btw. is added into the server location index.html stops working.

Will check their forums, I thought this was something specific to nginx.


#6

Well, you can try following:

location / {  
    try_files $uri $uri/ /index.html /index.php?$args;  
}  

It should achieve your goal. But for a better answer, it will be good to contact ISPConfig as this is something most likely issue (or expected behaviour) with ISPConfig.


#7

That worked awesome. Thanks!


#8