23

我将 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 配置为在 URL 中不区分大小写?

4

1 回答 1

32
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.
        }
    }
}
于 2013-08-24T08:50:09.063 回答