Home > Net >  nginx configuration to load files without trailing slash no redirect
nginx configuration to load files without trailing slash no redirect

Time:12-05

I want nginx to run /filename rendered as html file, /folder/ as folder (I mean loading /folder/index.html), and /filename.html as html file.

With default setup /filename not working. When I put a file as /filename to the server, it downloads the file.

I dont want any redirects, just load the files without trailing slash.

My current setup is

 location / {
          try_files $uri  @proxy;
          }

CodePudding user response:

Try adding default_type text/html; to your server configuration.

Details of my test:

server {
    server_name www.example.com;
    root    /var/www/example.com;

    default_type text/html;
}

Test directory structure:

├── afile
├── afile.html
└── afolder
    └── index.html

afile:

<html>
<b>html with no extension</b>
</html>

afile.html:

<html>
<b>html with an html extension</b>
</html>

afolder/index.html

<html>
<b>index.html</b>
</html>
  • Related