全部博文(61)
分类: LINUX
2015-11-03 17:05:44
最近有一项目需要移植到Linux下,功能简单来讲就是FTP上传+HTTP下载。
由于Windows操作系统中,文件名是不区分大小写的,而Linux系统是大小写敏感,导致对应开发人员及程序都感冒了!
解决分3步:
首先,使用FTP上传时,需要统一大小写。文件名和路径要统一使用大写或小写,推荐用小写。一般主流的FTP工具都支持此类转换:
然后,需要将已上传的目录和文件做一次转换。下例为递归将目录和文件改为小写:
1
2
|
#!/bin/bash
find -exec sh -c 'rm -f "$0" `echo "$0" | tr "[A-Z]" "[a-z]"` > /dev/null 2>&1' {} \;
|
最后,在HTTP前端做统一处理,将下载地址进行统一转换。
转换方法有3种:
1、使用perl模块(不推荐!Nginx官网已申明perl模块存在内存漏洞的可能,笔者在生产环境中有遇到,推测是在reload时发生的)
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;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; }
}
}
2、使用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、使用第3方模块(),示例如下:
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; }
}
}