Olivier Pons
Olivier Pons

Reputation: 15778

nginx: '/' url doesn't try index.html file

With this configuration, when I call "my.domainname.com/unity/index.html" manually, it works and it finds all the other files. When I try "my.domainname.com/unity/" it doesnt go to the default index.html file and returns a 403. What am I missing?

(most important are the latest lines, configuring when user wants to access to /unity path)

server {
  listen *:443 ssl;
  server_name "~^my\.domainname\..*$";

  index index.html index.htm;

  access_log /var/log/nginx/proxy-access.log proxylog;
  error_log /var/log/nginx/proxy-error.log error;

  ssl_certificate /var/lib/acme/live/my.domainname.com/fullchain;
  ssl_certificate_key /var/lib/acme/live/my.domainname.com/privkey;
  ssl_trusted_certificate /var/lib/acme/live/hive.battlesoop.fr/chain;
  ssl_stapling on;
  ssl_stapling_verify on;

  location '/.well-known/acme-challenge' {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Server $host;
    proxy_pass http://acmetool;
  }

  # Add CORS access to all = '*'
  add_header 'Access-Control-Allow-Origin' '*' always;
  add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
  add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept' always;
  add_header 'Access-Control-Allow-Credentials' 'true' always;

  # unity
  location ~* ^/unity(?<p>.*) {
    root /web/htdocs/my.domainname.com/unity;
    index index.html index.htm;
    try_files /$p =403;
    access_log off;
    expires 1h;
  }
}

Upvotes: 4

Views: 286

Answers (1)

Richard Smith
Richard Smith

Reputation: 49722

With try_files the index feature is triggered by a file term with a trailing /. See this document for details.

I couldn't get it working with your named capture though, but if you knock the "/unity" term off the end of the root statement, you can use the conventional approach.

For example:

location ~* ^/unity {
    root /web/htdocs/my.domainname.com;
    index index.html index.htm;
    try_files $uri $uri/ =403;
    access_log off;
    expires 1h;
}

Upvotes: 3

Related Questions