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

前端之家收集整理的这篇文章主要介绍了如何使Nginx使URL不区分大小写前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在使用Nginx做一个简单的演示网站,而我只是配置Nginx

@H_403_6@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.

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

最佳答案
@H_403_6@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.
        }
    }
}
原文链接:https://www.f2er.com/nginx/434642.html

猜你在找的Nginx相关文章