Nginx中URL不區分大小寫


1.需要Embedded Perl模塊支持
  本模塊允許在Nginx中直接執行Prel,或者通過SSI調用Perl。
  默認是不會編譯進Nginx的,如果你要使用,則要在編譯安裝Nginx指定:
./configure  --with-http_perl_module
  另外:操作系統中必須安裝:Perl5.6.1以上版本
已知問題:
    1 ) 如果Perl模塊執行長時間操作,例如:DNS查詢、數據庫查詢等,運行Perl腳本的工作進程將一直處於阻塞狀態,因此內置的Perl腳本應該非常簡單,執行盡可能快。
    2)Nginx在通過“Kill -HUP <pid>”命令重新加載配置文件時,可能會導致內存泄露。
詳細配置方法:
1.增加一個方法
    perl_set $url '
        sub {
                my $r = shift;
                my $re = lc($r->uri);
                return $re;
        }
    ';
2.增加一個判斷條件
        if ($uri ~ [A-Z]){
                rewrite ^(.*)$ $url last;
        }
說明:
    Perl需要Perl 5.6.1以上版本支持
整個配置文件如下:
-----------------------------------------------------------------------
#user  nobody;
worker_processes  1;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
    #access_log  logs/access.log  main;
    sendfile        on;
    tcp_nopush     on;
    #gzip  on;
    perl_set $url '
        sub {
                my $r = shift;
                my $re = lc($r->uri);
                return $re;
        }
    ';
    server {
        listen       80;
        server_name  localhost;
        if ($uri ~ [A-Z]){
                rewrite ^(.*)$ $url last;
        }
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        include       xx.cn/xx.conf;
    }
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM