如何使用Nginx使URL不区分大小写

19 nginx

我使用Nginx作为一个简单的演示网站,我只是像这样配置Nginx:

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

    location / {
        index           index.html;
        root            /home/www.abc.com/;
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的www.abc.com文件夹中,我有子文件夹命名Sub,里面有index.html文件.因此,当我尝试访问时www.abc.com/Sub/index.html,它工作正常.如果我访问www.abc.com/sub/index.html,它会返回404.

如何在URL中配置Nginx不区分大小写?

Fle*_*der 27

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.
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 我认为这将匹配包含*/sub /的所有网址*(例如,它也匹配"example.com/yellow/sub/").它应该是`location~*^/sub /`(带插入符号). (4认同)