2015-11-24 107 views
1

我一直在試圖找出什麼是錯的,我的regex或nginx config。我有以下位置塊在我的nginx的配置nginx匹配位置與正則表達式

location ~ /v1/(tests|my/.*/tests|your/.*/test|our/.*/testers) { 
    proxy_pass http://127.0.0.1:8000; 
} 

的Nginx在端口8080運行,我有一個簡單的測試Web服務器上的端口8000運行。我用下列路徑

  • http://localhost:8080/v1/tests(工程)
  • http://localhost:8080/v1/my/a1/tests(工程)
  • http://localhost:8080/v1/my/%20/tests(工程)
  • http://localhost:8080/v1/my//tests(與 nginx的服務器上失敗)
  • http://localhost:8080/v1/my/%2F/tests測試本(在nginx服務器上失敗,)

我想知道爲什麼這是因爲我匹配my/.*/tests,它應該也匹配空字符串呢?我錯過了什麼嗎?

感謝幫助!

+0

你在你的正則表達式中有'writters'而不是'tests'。 –

+0

哪臺服務器生成404? –

+0

@RichardSmith運行nginx的服務器返回** 404 ** – digerati

回答

0

nginx在執行測試(例如正則表達式)之前對URI進行規範化。標準化過程的一部分是將連續的/ s摺疊成單個/

結果是,my/tests不是您的正則表達式的有效匹配。

+0

謝謝,只需在此處添加引用,即http://nginx.org/en/docs/http/ngx_http_core_module。 HTML#位置 – digerati