Another way is with module pure c ngx_http_lower_upper_case because load perl is resource usage high:
location ~ [A-Z] { lower $uri_lowercase "$request_uri"; rewrite ^(.*)$ $scheme://$host$uri_lowercase; }