2017-06-14 81 views
0

我有下面的Apache配置指令:下面阿帕奇ProxyPassMatch循环请求

ProxyPass "/info" unix:/var/run/docker.sock|http://localhost/info 
ProxyPass "/version" unix:/var/run/docker.sock|http://localhost/version 
ProxyPass "/containers/json" unix:/var/run/docker.sock|http://localhost/containers/json 
ProxyPassMatch "^/containers/([^/]+)/json$" unix:/var/run/docker.sock|http://localhost/containers/$1/json 
ProxyPass/"!" 

要求正常工作:

http://server.domain/info 
http://server.domain/version 
http://server.domain/containers/json 

但是这一次不工作:

http://server.domain/containers/asd123qwe/json 

我期待ProxyPassMatch生成如下请求:

http://localhost/containers/asd123qwe/json 

配置是否可能生成循环条件? ProxyPassMatch应该再次在Apache上生成内部请求,还是按照配置中的说明将其简单地转发到套接字?

使用log_forensic_module我得到如下日志,这就是为什么我正在考虑一些无限循环请求作为问题。对不起,长输出!

GET /containers/f1063abfd92409/json HTTP/1.1|Host:server.domain%3a8080|Connection:keep-alive|Upgrade-Insecure-Requests:1|User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36|Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8|Accept-Encoding:gzip, deflate, sdch|Accept-Language:en-US,en;q=0.8,pt-BR;q=0.6,pt;q=0.4 
GET /containers/f1063abfd92409/json HTTP/1.1|Host:localhost|Upgrade-Insecure-Requests:1|User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36|Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8|Accept-Encoding:gzip, deflate, sdch|Accept-Language:en-US,en;q=0.8,pt-BR;q=0.6,pt;q=0.4|X-Forwarded-For:10.255.0.2|X-Forwarded-Host:server.domain%3a8080|X-Forwarded-Server:127.0.0.1|Connection:close 
GET /containers/f1063abfd92409/json HTTP/1.1|Host:localhost|Upgrade-Insecure-Requests:1|User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36|Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8|Accept-Encoding:gzip, deflate, sdch|Accept-Language:en-US,en;q=0.8,pt-BR;q=0.6,pt;q=0.4|X-Forwarded-For:10.255.0.2, 127.0.0.1|X-Forwarded-Host:server.domain%3a8080, localhost|X-Forwarded-Server:127.0.0.1, 127.0.0.1|Connection:close 
GET /containers/f1063abfd92409/json HTTP/1.1|Host:localhost|Upgrade-Insecure-Requests:1|User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36|Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8|Accept-Encoding:gzip, deflate, sdch|Accept-Language:en-US,en;q=0.8,pt-BR;q=0.6,pt;q=0.4|X-Forwarded-For:10.255.0.2, 127.0.0.1, 127.0.0.1|X-Forwarded-Host:server.domain%3a8080, localhost, localhost|X-Forwarded-Server:127.0.0.1, 127.0.0.1, 127.0.0.1|Connection:close 
GET /containers/f1063abfd92409/json HTTP/1.1|Host:localhost|Upgrade-Insecure-Requests:1|User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36|Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8|Accept-Encoding:gzip, deflate, sdch|Accept-Language:en-US,en;q=0.8,pt-BR;q=0.6,pt;q=0.4|X-Forwarded-For:10.255.0.2, 127.0.0.1, 127.0.0.1, 127.0.0.1|X-Forwarded-Host:server.domain%3a8080, localhost, localhost, localhost|X-Forwarded-Server:127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1|Connection:close 
GET /containers/f1063abfd92409/json HTTP/1.1|Host:localhost|Upgrade-Insecure-Requests:1|User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36|Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8|Accept-Encoding:gzip, deflate, sdch|Accept-Language:en-US,en;q=0.8,pt-BR;q=0.6,pt;q=0.4|X-Forwarded-For:10.255.0.2, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1|X-Forwarded-Host:server.domain%3a8080, localhost, localhost, localhost, localhost|X-Forwarded-Server:127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1|Connection:close 
GET /containers/f1063abfd92409/json HTTP/1.1|Host:localhost|Upgrade-Insecure-Requests:1|User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36|Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8|Accept-Encoding:gzip, deflate, sdch|Accept-Language:en-US,en;q=0.8,pt-BR;q=0.6,pt;q=0.4|X-Forwarded-For:10.255.0.2, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1|X-Forwarded-Host:server.domain%3a8080, localhost, localhost, localhost, localhost, localhost|X-Forwarded-Server:127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1|Connection:close 
GET /containers/f1063abfd92409/json HTTP/1.1|Host:localhost|Upgrade-Insecure-Requests:1|User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36|Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8|Accept-Encoding:gzip, deflate, sdch|Accept-Language:en-US,en;q=0.8,pt-BR;q=0.6,pt;q=0.4|X-Forwarded-For:10.255.0.2, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1|X-Forwarded-Host:server.domain%3a8080, localhost, localhost, localhost, localhost, localhost, localhost|X-Forwarded-Server:127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1|Connection:close 
GET /containers/f1063abfd92409/json HTTP/1.1|Host:localhost|Upgrade-Insecure-Requests:1|User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36|Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8|Accept-Encoding:gzip, deflate, sdch|Accept-Language:en-US,en;q=0.8,pt-BR;q=0.6,pt;q=0.4|X-Forwarded-For:10.255.0.2, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1|X-Forwarded-Host:server.domain%3a8080, localhost, localhost, localhost, localhost, localhost, localhost, localhost|X-Forwarded-Server:127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1|Connection:close 
GET /containers/f1063abfd92409/json HTTP/1.1|Host:localhost|Upgrade-Insecure-Requests:1|User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36|Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8|Accept-Encoding:gzip, deflate, sdch|Accept-Language:en-US,en;q=0.8,pt-BR;q=0.6,pt;q=0.4|X-Forwarded-For:10.255.0.2, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1|X-Forwarded-Host:server.domain%3a8080, localhost, localhost, localhost, localhost, localhost, localhost, localhost, localhost|X-Forwarded-Server:127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1, 127.0.0.1|Connection:close 
+0

我不是Apache的专家,但你的正则表达式应该工作得很好,所以我建议你寻找更广泛的问题的原因。 –

+0

@DmitryVolkov感谢您的评论,我正在努力做到这一点,但我无法找到任何有关它为什么不起作用的好解释的地方。我同意你的看法,它应该工作。 – Azize

回答

0

只要做到:

^\/containers\/[a-zA-Z0-9_]+?\/json$ 

这将懒洋洋地匹配任何字母数字,直到下一个forwardslash /,这就是我假设你想要的。

+0

感谢您的文章,您是正确的,我希望任何字符,直到'/',但我不知道为什么它不工作。 – Azize

+0

@Azize看到我的编辑,我认为你需要摆脱正斜线。 – Jokab

+0

Stil不工作,这很奇怪。我把括号放在它上面,否则我不能在代理URL上使用它。这就是:'ProxyPassMatch'^ \/containers \ /([a-zA-Z0-9 _] +?)\/json $“unix:/var/run/docker.sock | http:// localhost/containers/$ 1/json' – Azize