2013-12-11 111 views
0

我使用nginx的1.4.3,並試圖匹配長字符串或子長的URL是這樣的:匹配子在nginx的位置

  1. 長的URL沒有任何的正則表達式

    location ~* /index.php?/english/Kbase/Article/IRS { 
          proxy_pass   http://backend; 
          proxy_cache  kbase-cache; 
          <...> 
    } 
    

    結果:沒有什麼是匹配的,但這樣的網址存在。

  2. 長的URL與正則表達式

    location ~* /idx/index.php?/Kbase/branch/Article/\d+.* { 
          proxy_pass   http://backend; 
          <....> 
    } 
    

    結果:沒有匹配的新聞

  3. location ~* /idx/index.php?/Tickets/Ticket/ListAll/[\d,]*/6/[\d,]*/[\d,]*.* { 
          proxy_pass   http://backend; 
          <....> 
    } 
    

    結果:沒有匹配的新聞

  4. location ~* \.(jpg|jpeg|gif|png)$ { 
          root /opt/httpdocs;    
    } 
    

    結果:工作正常。

  5. location/{ 
          proxy_pass   http://backend; 
    } 
    

    結果:工作正常。

例子1,2,3:我嘗試了所有的變化來匹配至少子字符串。第條。, ,它甚至不起作用。* IRS不起作用,但第四個例子工作正常。

我錯過了什麼或什麼?請指教。

+3

的'?'意味着前述'p'是可選的。你的意思是一個字面的??你需要轉義它('\?')。 –

+0

是的,即使我逃脫\?它仍然不匹配。甚至最簡單的表單位置〜。* IRS $ {return 410; }不起作用。我錯過了什麼? – user3091890

回答

0

您缺少必須終止正則表達式的$符號。

E.g.

location ~* /idx/index.php\?/Kbase/branch/Article/\d+.* { 

必須是

location ~* /idx/index.php\?/Kbase/branch/Article/\d+.*$ {