日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

nginx php 大小写问题,Nginx实现url请求不区分大小写

發布時間:2023/11/27 生活经验 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 nginx php 大小写问题,Nginx实现url请求不区分大小写 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

如果你將跑在Windows下的項目(如:php)遷移到

解決方法有大概4種:

1、 url rewrite

2、 perl模塊

3、 lua模塊

4、 ngx_http_lower_upper_case

第一種方法適用于有規則的或者較少的url需要轉換,如果有大量并無規則的請用下面幾種方法

第二、三、四種方法前提是Linux系統本地文件是小寫,原理是將url請求轉換成小寫來處理

perl模塊(不推薦!),方法如下(《lnmp一鍵安裝包》安裝后執行下面):

cd lnmp/src/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'

在已經編譯的參數后面加上 –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

解決方法(

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的開源項目,在

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_kitwget https://github.com/chaoslawful/lua-nginx-module/archive/v0.9.2.tar.gz#nginx_lua_moduletar xzfLuaJIT-2.0.2.tar.gz

tar xzf v0.2.19.tar.gz

tar xzf v0.9.2.tar.gz

cdLuaJIT-2.0.2make&&make install

export LUAJIT_LIB=/usr/local/lib

export LUAJIT_INC=/usr/local/include/luajit-2.0

cd nginx-1.4.4make clean#清除已經編譯出的nginx# /usr/local/nginx/sbin/nginx -V #獲取已編譯參數nginx version:nginx/1.4.4built by gcc4.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'

重新編譯

./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)';

}

}

總結

以上是生活随笔為你收集整理的nginx php 大小写问题,Nginx实现url请求不区分大小写的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。