search

Home  >  Q&A  >  body text

How to set nginx to make files in a directory not case sensitive

The cache is dynamically generated. It is more efficient to read these cache files directly through the URL. However, cache letters are all lowercase. For example http://xxx/ooo/abc.jpg

When the user reads http://xxx/ooo/ABC.jpg, the cache cannot be located (error report

How can I ignore the case of files only in the path ooo/?

给我你的怀抱给我你的怀抱2782 days ago852

reply all(3)I'll reply

  • 仅有的幸福

    仅有的幸福2017-05-16 17:30:49

    I didn’t even read the question clearly, so I posted a link. Unfortunately, I don’t have enough reputation, otherwise I would definitely step on you
    Let me answer the poster’s question, two options:
    1. Use the Perl Moudle officially provided by nginx. Note that this module is not automatically loaded. When you need to run the configuration file, add --with-httpperlmodule. First, the location must match the ooo directory, and then match the remaining uri. If there are uppercase letters, call perl to convert all urls to lowercase, and then rewrite, refer to the configuration code:

        #测试perl的统一转小写功能
        perl_set    $url '
            sub {
                    my $r = shift;
                    my $lurl = lc($r->uri);
                    return $lurl;
            }
        ';
    
        location ~* ^/ooo/ {
            if ($uri ~ [A-Z]) {
                rewrite ^(.*)$  $url    premanent;
            }   
    
            root ooo所在的根目录;
        }
    
    
    1. Google found that someone provided a third-party module for nginx. The usage is relatively clear, so I posted the link directly: https://github.com/replay/ngx_http_lower_upper_case

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-16 17:30:49

    You can use lua, perl for processing, or you can write modules for processing. It has been given above, so I won’t repeat it.

    reply
    0
  • PHP中文网

    PHP中文网2017-05-16 17:30:49

    http://sookk8.blog.51cto.com/455855/564705

    reply
    0
  • Cancelreply