Chinaunix首页 | 论坛 | 博客
  • 博客访问: 315269
  • 博文数量: 61
  • 博客积分: 365
  • 博客等级: 一等列兵
  • 技术积分: 611
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-04 11:39
文章分类

全部博文(61)

文章存档

2017年(15)

2016年(13)

2015年(19)

2014年(12)

2013年(2)

我的朋友

分类: LINUX

2015-11-03 17:05:44

 最近有一项目需要移植到Linux下,功能简单来讲就是FTP上传+HTTP下载。

    由于Windows操作系统中,文件名是不区分大小写的,而Linux系统是大小写敏感,导致对应开发人员及程序都感冒了!

  解决分3步:

    首先,使用FTP上传时,需要统一大小写。文件名和路径要统一使用大写或小写,推荐用小写。一般主流的FTP工具都支持此类转换:

    DGWG4NL3GM2Q`3A70SE}8ZB

    然后,需要将已上传的目录和文件做一次转换。下例为递归将目录和文件改为小写:

?
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; } 
  } 
}

阅读(942) | 评论(0) | 转发(0) |
0

上一篇:linux内核调优

下一篇:python命令自动补全

给主人留下些什么吧!~~