IT袋

当前位置:主页 > 经验教程 > 系统教程 >

如何实现网站url不分大小写

如何实现Linux nginx网站url不分大小写(2)

更新:2023-08-08 08:48:08 来源:IT袋 作者:马勇
导读:如何实现网站url不分大小写,--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 +%

如何实现网站url不分大小写


--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语法,如下:

cd lnmp/src
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.720120313(RedHat4.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'
重新编译Nginx:

./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 \
--add-module=../lua-nginx-module-0.9.2--add-module=../ngx_devel_kit-0.2.19
make
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx$(date +%m%d)#备份nginx原文件
service nginx stop
make install #直接安装,如果只覆盖nginx,可能会报错
ldconfig #重新读取库文件,否则报错/usr/local/nginx/sbin/nginx -t
修改配置文件(如:/usr/local/nginx/conf/vhost/demo.linuxeye.com.conf):

location /{if($uri ~[A-Z]){
rewrite_by_lua 'return ngx.redirect(string.lower(ngx.var.uri),ngx.HTTP_MOVED_PERMANENTLY)';}}
ngx_http_lower_upper_case模块
参考:https://github.com/replay/ngx_http_lower_upper_case

IT袋小编提醒:以上方法步骤需要根据您linux文件下载的路径或nginx...等配置来做对应修改再编译,不过经过IT袋小编实战测试,这方法并不科学,还是推荐大家使用windows服务器原生就支持url大小写混输,不区分大小写,其实windows服务器系统也多耗用不了多少配置。

以上就是如何实现Linux nginx网站url不分大小写的详细方法介绍,大家作为一个参考建议.

相关阅读