歡迎您光臨本站 註冊首頁

nigix 正則達式問題(高手請進)

←手機掃碼閱讀     火星人 @ 2014-03-04 , reply:0

nigix 正則達式問題(高手請進)

我的web伺服器是用nginx架設的。現在我正在做一個測試,利用geoip模塊來禁止特定國家IP訪問,現在的一個問題是,只是被禁止的國家ip訪問我們的網站二級聯接都會自動導向http://www.example.com/error403.com這個文件,但首面不就是不行,也就是說輸入http://www.example.com時還是無法定向error403.com這個文件。 不知道 為什麼,特向高手請教這條規則應該如何書寫。
《解決方案》

你先貼出你的配置,好讓別人指正啊。 。。
《解決方案》

^http:\/\/.*example.com\/.*
表達式大概是這個樣子,但實施就不知道了

http://www.example.com/error403.com
《解決方案》

server
{
    listen 80;
    server_name pl.sourcingmap.com;
    index index.html index.htm index.php;
    root /export/wwwsourcingmap;
    if (-f $request_filename/index.html)
    {
        rewrite (.*) $1/index.html break;
    }
    if (-f $request_filename/index.htm)
    {
        rewrite (.*) $1/index.htm break;
    }
    if (-f $request_filename/index.php)
    {
        rewrite (.*) $1/index.php break;
    }
    if ($geo = 'CN' )
        {
        rewrite (.*) /error403.html break;
        }
    error_page 404 /error_info.php;
    error_page 403 /error403.html;

    rewrite ^/\\$ /index.php;
    rewrite ^/card$ /welcome.html;
    rewrite ^(.*)iphone-skin-case-c-983_1389.html$ /iphone-cases-c-983_1389.html;
    rewrite ^(.*)pda-laptop-batteries-c-1355_1446.html$ /pda-laptop-batteries-c-987_1446.html;
    rewrite ^(.*)laptop-adapters-c-1355_1758.html$ /laptop-adapters-c-987_1758.html;
    rewrite ^(.*)laptop-accessories-c-1355_1546.html$ /laptop-accessories-c-987_1546.html;
    rewrite ^(.*)laptop-keyboard-cases-c-987_1355_1796.html$ /laptop-keyboard-cases-c-987_1796.html;
    rewrite ^(.*)laptop-carrying-bags-c-1355_1794.html$ /laptop-carrying-bags-c-987_1794.html;
    rewrite ^(.*)-p-(.*).html$ "/product_info.php?products_id=$2&%{QUERY_STRING}";
    rewrite ^(.*)-p-(.*)/osCsid/(.*) /product_info.php?products_id=$2;
    rewrite ^(.*)-c-(.*).html$ "/index.php?cPath=$2&%{QUERY_STRING}";
    rewrite ^(.*)-m-(+).html$ "/index.php?manufacturers_id=$2&%{QUERY_STRING}";
    rewrite ^(.*)-pi-(+).html$ "/popup_image.php?pID=$2&%{QUERY_STRING}";
    rewrite ^(.*)-t-(+).html$ "/articles.php?tPath=$2&%{QUERY_STRING}";
    rewrite ^(.*)-a-(+).html$ "/article_info.php?articles_id=$2&%{QUERY_STRING}";
    rewrite ^(.*)-pr-(+).html$ "/product_reviews.php?products_id=$2&%{QUERY_STRING}";
    rewrite ^(.*)-pri-(+).html$ "/product_reviews_info.php?products_id=$2&%{QUERY_STRING}";
    rewrite ^(.*)-i-(+).html$ "/information.php?info_id=$2&%{QUERY_STRING}";
    rewrite ^/nfl_gear_products.html$ /advanced_search_result.php?searchbar=1&keywords=NFL+Gear&searchType=all;
    rewrite index.php/cPath/(.+) /index.php?cPath=$1;
    rewrite product_info.php/products_id/(.+) /product_info.php?products_id=$1;
    rewrite product_reviews_info.php/products_id/(.+)/reviews_id/(.+) /product_reviews_info.php?products_id=$1&reviews_id=$2;
    rewrite product_info.php/cPath/(.+)/products_id/(.+) /product_info.php?cPath=$1&products_id=$2;

    location ~ .*\.php?$
    {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /export/wwwsourcingmap/$fastcgi_script_name;
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_index   index.php;
    }
#       location  / {
#                       deny from CN,HK;
#                       allow from all;
#                       }
   #location /NginxStatus
  #{
  #  stub_status on;
   # access_log off;
    #}
        location ~* ^/admin/{
                root /export/wwwsourcingmap/admin;
                auth_basic      "Restricted";
                auth_basic_user_file    "/usr/local/nginx/conf/htpasswd";
                }
        location = /_.gif {
                        empty_gif;
                          }
        location /dynamic_request {
                set $memcached_key $uri;
                if ($args ~* format=json) { rewrite ^/dynamic_request/?(.*)$ /dynamic_request.js$1 break; }
                if ($args ~* format=xml) { rewrite ^/dynamic_request/?(.*)$ /dynamic_request.sml$1 break; }
                memcached_pass 127.0.0.1:11211;
                default_type    text/html;
                memcached_buffer_size 8096;
                error_page      404 = @dynamic_request;

                   }
#       location ~/\.ht {
#               deny all;
#                       }

}


紅色部分為按國家區碼限制訪問的代碼。按三樓的規則設置的話,連二級聯接都沒有效果了

[火星人 ] nigix 正則達式問題(高手請進)已經有395次圍觀

http://coctec.com/docs/service/show-post-26413.html