假如你将跑在Windows下的项目(如:php)迁移到Linux下,由于Windows操纵系统中,文件名是不区分巨细写的;而Linux系统是巨细写敏感,会导致有些网页呈现404环境。
办理要领有或许4种:
1、 url rewrite
2、 perl模块
3、 lua模块
4、 ngx_http_lower_upper_case
第一种要领合用于有法则的可能较少的url需要转换,假如有大量并无法则的请用下面几种要领
第二、三、四种要领前提是Linux系统当地文件是小写,道理是将url请求转换成小写来处理惩罚
perl模块(不推荐!Nginx官网已申明perl模块存在内存裂痕的大概),要领如下(《lnmp一键安装包》安装后执行下面):
cd lnmp/src/nginx-1.4.4make clean #排除已经编译出的nginx
# /usr/local/nginx/sbin/nginx -V #获取已编译参数
nginx version: nginx/1.4.4
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC)
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --with-ld-opt='-ljemalloc'
在已经编译的参数后头加上 --with-http_perl_module ,,如下:
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module--with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --with-ld-opt='-ljemalloc'
--with-http_perl_module
大概会报如下错误:
Can't locate ExtUtils/Embed.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .).BEGIN failed--compilation aborted.
./configure: error: perl module ExtUtils::Embed is required
办理要领(CentOS):
yum -y install perl-devel perl-ExtUtils-Embed再次编译:
make clean./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module
--with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --with-ld-opt='-ljemalloc'
--with-http_perl_module
make
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx$(date +%m%d) #备份nginx原文件
service nginx stop
make install #直接安装,假如只包围nginx,会有报错
/usr/local/nginx/sbin/nginx -t
修改设置主文件(/usr/local/nginx/conf/nginx.conf):
perl_set $url 'sub {
my $r = shift;
my $re = lc($r->uri);
return $re;
}
';
修改虚拟主机设置文件(如:/usr/local/nginx/conf/vhost/demo.linuxeye.com.conf):
if ($uri ~ [A-Z]){rewrite ^(.*)$ $url last;
}
lua模块(推荐!)
lua-nginx-module来自大牛agentzh的开源项目,在Nginx中嵌入Lua语言,使之可以支持强大Lua语法,如下:
wget http://luajit.org/download/LuaJIT-2.0.2.tar.gz
wget https://github.com/simpl/ngx_devel_kit/archive/v0.2.19.tar.gz #ngx_devel_kit
wget https://github.com/chaoslawful/lua-nginx-module/archive/v0.9.2.tar.gz #nginx_lua_module
tar xzf LuaJIT-2.0.2.tar.gz
tar xzf v0.2.19.tar.gz
tar xzf v0.9.2.tar.gz
cd LuaJIT-2.0.2
make && make install
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.0
cd nginx-1.4.4
make clean #排除已经编译出的nginx
# /usr/local/nginx/sbin/nginx -V #获取已编译参数
nginx version: nginx/1.4.4
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC)
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --with-ld-opt='-ljemalloc'