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

时间:2013-08-24 06:04:41

标签: nginx

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

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

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

在我的www.abc.com文件夹中,我有一个名为Sub的子文件夹,里面有index.html个文件。因此,当我尝试访问www.abc.com/Sub/index.html时,它运行正常。如果我访问www.abc.com/sub/index.html,则会返回404

如何在网址中将Nginx配置为不区分大小写?

1 个答案:

答案 0 :(得分:25)

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.
        }
    }
}