1

So I'm trying to setup a default nginx config file that can be deployed across numerous docker image with different website configs in each container. It is currently set as below:

server {
   listen 80 default_server;

   root /var/www/;
   index index.php index.html;

   server_name localhost;
   include php5-fpm.conf;


   location / {
           try_files $uri $uri/ /index.php?q=$request_uri;
   }

   location /status {
           stub_status on;
           access_log   off;
           allow 127.0.0.1;
           deny all;
   }

}

The problem is that it doesn't work for static sites that use index.htm or index.html

I can edit the location section like below and then the site will work. Is there any way to get nginx to use a wildcard, so index.* and it will use whichever index file it finds? index.* by itself does not work so not sure what needs to be added/removed...

       location / {
           try_files $uri /index.htm?q=$request_uri;
   }

1 Answer 1

1

You're fixated on the wrong part of try_files.

The part relevant to what you want is $uri/, with the trailing slash, which you seem to have removed. This bit causes nginx to try all of the files listed in the index directive.

You should put this part back in try_files and then edit the index directive to include the filenames you want.

1
  • Thanks, Yes I added index.htm to the index directive and it works 100%. I was fixated on the wrong part as you said.
    – SyphonxZA
    Jul 18, 2018 at 14:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .