https://my.oschina.net/kisops/blog/151087html
最近有一項目須要移植到Linux下,功能簡單來說就是FTP上傳+HTTP下載。前端
因爲Windows操做系統中,文件名是不區分大小寫的,而Linux系統是大小寫敏感,致使對應開發人員及程序都感冒了!python
解決分3步:git
首先,使用FTP上傳時,須要統一大小寫。文件名和路徑要統一使用大寫或小寫,推薦用小寫。通常主流的FTP工具都支持此類轉換:github
而後,須要將已上傳的目錄和文件作一次轉換。下例爲遞歸將目錄和文件改成小寫:bash
#!/bin/bashfind -exec sh -c 'rm -f "$0" `echo "$0" | tr "[A-Z]" "[a-z]"` > /dev/null 2>&1' {} \;
最後,在HTTP前端作統一處理,將下載地址進行統一轉換。ide
轉換方法有3種:svn
一、使用perl模塊(不推薦!Nginx官網已申明perl模塊存在內存漏洞的可能,筆者在生產環境中有遇到,推測是在reload時發生的)工具
user nobody nobody;
worker_processes 8;
error_log /data/log/tengine/error.log error;
pid /var/run/tengine.pid;luaevents {
use epoll;
worker_connections 81920;
}http {
include mime.types;
default_type text/plain;
access_log off;
sendfile on;
server_tokens off;
keepalive_timeout 120;perl_set $url '
sub {
my $r = shift;
my $re = lc($r->uri);
return $re;
}
';
server {
listen 80 backlog=8192;
server_name _;
charset utf-8;location / {
if ($uri ~ [A-Z]){ rewrite ^(.*)$ $url last; }
root /usr/share/tengine/html;
index index.html;
}location ~ ^(.*)\/\.(svn|git|hg|bzr|cvs)\/ { deny all; access_log off; log_not_found off; }
}
}
二、使用lua模塊(推薦!),示例以下:
user nobody nobody;
worker_processes 8;
error_log /data/log/tengine/error.log error;
pid /var/run/tengine.pid;events {
use epoll;
worker_connections 81920;
}dso { # DSO module for Tengine
load ngx_http_lua_module.so;
}http {
include mime.types;
default_type text/plain;
access_log off;
sendfile on;
server_tokens off;
keepalive_timeout 120;server {
listen 80 backlog=8192;
server_name _;
charset utf-8;location / {
if ($uri ~ [A-Z]){
rewrite_by_lua 'return ngx.redirect(string.lower(ngx.var.uri),ngx.HTTP_MOVED_PERMANENTLY)';
}
root /usr/share/tengine/html;
index index.html;
}location ~ ^(.*)\/\.(svn|git|hg|bzr|cvs)\/ { deny all; access_log off; log_not_found off; }
}
}
三、使用第3方模塊(ngx_http_lower_upper_case),示例以下:
user nobody nobody;
worker_processes 8;
error_log /data/log/tengine/error.log error;
pid /var/run/tengine.pid;events {
use epoll;
worker_connections 81920;
}http {
include mime.types;
default_type text/plain;
access_log off;
sendfile on;
server_tokens off;
keepalive_timeout 120;server {
listen 80 backlog=8192;
server_name _;
charset utf-8;location / {
if ($uri ~ [A-Z]){
lower $url "$uri";
rewrite ^(.*)$ $url redirect;
}
root /usr/share/tengine/html;
index index.html;
}location ~ ^(.*)\/\.(svn|git|hg|bzr|cvs)\/ { deny all; access_log off; log_not_found off; } } }