【问题标题】:How to make URL case insensitive with Nginx如何使用 Nginx 使 URL 不区分大小写
【发布时间】:2013-08-24 06:04:40
【问题描述】:

我正在使用 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 中不区分大小写?

【问题讨论】:

标签: nginx


【解决方案1】:
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.
        }
    }
}

【讨论】:

  • 上述解决方案对我不起作用..你能帮帮我吗。~* 仅适用于 if 条件
  • 我认为这将匹配所有 包含 /sub/ 的网址(例如,它也将匹配“example.com/yellow/sub/”)。它应该是location ~* ^/sub/(带有插入符号)。
猜你喜欢
  • 2012-05-25
  • 2011-10-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-01
相关资源
最近更新 更多