Make my_webapp paths case insensitive with Nginx

My YunoHost server

Hardware: VPS bought online
YunoHost version: 11.0.10.2
I have access to my server : Through SSH + through the webadmin
Are you in a special context or did you perform some particular tweaking on your YunoHost instance ? : no

Description of my issue

I quit using Netlify and I am self hosting my website with YunoHost now.

There are some things that Netlify fixed automatically, but that break here.

In particular, I noticed that URLs just became case sensitive, while they were case insensitive before. As an example, https://tommi.space/People works, and https://tommi.space/people does not.

How could I fix this in Nginx without breaking anything else in YunoHost?

Note: tommi.space is my_webapp’s domain, and also my main TLD. I use many others sub-domains on the server, for example server.tommi.space or stream.tommi.space. I do not want to mess things up for the subdomains by changing something in tommi.space Nginx configuration.

Could you help me fix this?

Hello, I hate to be too persistent and annoying, but I would really appreciate some help about this! Could anyone give me some insights?

Please :pray:t3:
@tituspijean :heart::heart:

After a quick Internet search and per How to make URL case insensitive with Nginx - Stack Overflow, you need to alter your NGINX conf file with sudo nano /etc/nginx/conf.d/tommi.space.d/my_webapp.conf.
In there, replace the first location line with:

location ~* ^/ {

Save and exit with CTRL+O then CTRL+X.

Check that NGINX is happy with nginx -t.

If no complains arise, reload NGINX sudo systemctl reload nginx.

Thanks a lot for your help! Unfortunately, now if I type the correct URL but changing the letters case, I get error 500. What am I doing wrong?

Here is the content of my /etc/nginx/conf.d/tommi.space.d/my_webapp.conf.

(sudo nginx -t gives all ok as result)

#sub_path_only rewrite ^/$ / permanent;
location ~* ^/ {

    # Path to source
    alias /var/www/my_webapp/www/;

    # Default indexes and catch-all
    index index.html;
    try_files $uri $uri/ /index.php?$args;

    # Prevent useless logs
    #location = /favicon.ico {
    #    log_not_found off;
    #    access_log off;
    #}
    #location = /robots.txt {
    #    allow all;
    #    log_not_found off;
    #    access_log off;
    #}

    # Deny access to hidden files and directories
    location ~ ^/(.+/|)\.(?!well-known\/) {
        deny all;
    }

    # Include SSOWAT user panel.
    include conf.d/yunohost_panel.conf.inc;
}

UPDATE: I have many problems:

  • the error I mentioned in the post above
  • visiting https://tommi.space redirects to https://tommi.space/index.html/, therefore of course I get an error… why?
  • I have been meddling with Cache-Control but I cannot change the cache timeout…

this is the config I am using now on tommi.space

#sub_path_only rewrite ^/$ / permanent;
location ~* ^/ {

    # Path to source
    alias /var/www/my_webapp/www/;

    # Default indexes and catch-all
    index index.html;
    try_files $uri $uri/ /index.php?$args;

    # Prevent useless logs
    #location = /favicon.ico {
    #    log_not_found off;
    #    access_log off;
    #}
    #location = /robots.txt {
    #    allow all;
    #    log_not_found off;
    #    access_log off;
    #}

    # Deny access to hidden files and directories
    location ~ ^/(.+/|)\.(?!well-known\/) {
        deny all;
    }

    # Include SSOWAT user panel.
    #include conf.d/yunohost_panel.conf.inc;
}

location ~* \.(png|jpg|jpeg|gif|webp|avif|jxl|pdf|svg)$ {
        expires 1y;
        add_header Cache-Control "public, no-transform";
        more_set_headers "Strict-Transport-Security : max-age=63072000; includeSubDomains; preload";
}

location ~* \.(js|css|html|swf)$ {
        expires 15d;
        add_header Cache-Control "public, no-transform";
}

Can you share your NGINX error log, so that we know which URL triggers the error 500?

Sure! Here are all the logs.

Thanks a lot!

OK so there’s a redirection loop, seemingly because the try_files directive indeed sends you to /index.php which starts by / so it loads again the same location block. Try editing the line to remove the leading slash:

Check that NGINX is happy with nginx -t.
If no complain arises, reload NGINX sudo systemctl reload nginx.

Got it. Now it works, but the error given is 404.

I am trying to make every URL lowercase in my output, but I do not understand why some stay uppercase…