How to make URL case insensitive with Nginx

2020-02-26 04:40发布

I am using Nginx for a simple demo website, and I just configure the Nginx like this:

server {
    listen          80;
    server_name     www.abc.com;

    location / {
        index           index.html;
        root            /home/www.abc.com/;
    }
}

In my www.abc.com folder, I have sub-folder named Sub, and inside has index.html file. So when I try to visit www.abc.com/Sub/index.html, then it works fine. If I visit www.abc.com/sub/index.html, it returns 404.

How to configure the Nginx to case-insensitive in URL?

标签: nginx
1条回答
来,给爷笑一个
2楼-- · 2020-02-26 05:06
server {
    # Default, you don't need this!
    #listen          80;

    server_name     www.abc.com;

    # Index and root are global configurations for the whole server.
    index           index.html;
    root            /home/www.abc.com/;

    location / {
        location ~* ^/sub/ {
            # The tilde and asterisks ensure that this location will
            # be matched case insensitive. nginx does not support
            # setting absolutely everything to be case insensitive.
            # The reason is easy, it's costly in terms of performance.
        }
    }
}
查看更多
登录 后发表回答