%0 is not replaced by server name when used with Apache's ProxyPassMatch

烂漫一生 提交于 2020-01-13 03:54:26

问题


Problem:

%0 is not replaced by server name (i.e. test.local) when used with ProxyPassMatch.

<VirtualHost *:80>

  UseCanonicalName Off

  # %0 is replaced by server name (works)
  VirtualDocumentRoot /Users/mattes/sites/%0

  # %0 is replaced by an empty string (problem!)
  ProxyPassMatch ^(/.*\.php)$ fcgi://127.0.0.1:9000/Users/mattes/sites/%0/$1

</VirtualHost>

Work-around:

I found an interesting blog post here: http://holtstrom.com/michael/blog/post/225/Apache-2.2-Proxy.html. Basically, Michael uses RewriteEngine to save variables for later usage. Something like this will work, for example:

<VirtualHost *:80>

  UseCanonicalName Off
  VirtualDocumentRoot /Users/mattes/sites/%0

  RewriteEngine On
  RewriteRule .* - [E=SERVER_NAME:%{SERVER_NAME}]
  ProxyPassInterpolateEnv On
  ProxyPassMatch ^(/.*\.php)$ fcgi://127.0.0.1:9000/Users/mattes/sites/ \
                                                    ${SERVER_NAME}$1 interpolate

</VirtualHost>

While it works, i consider this to be a not-so-nice work-around. I am also getting errors like "AH00111: Config variable ${SERVER_NAME} is not defined".


Has anybody an idea how to solve this?


回答1:


I'm using this configuration with Apache 2.4:

<VirtualHost *:8080>
    UseCanonicalName Off
    VirtualDocumentRoot "/usr/local/apache/vhosts/%0"

    RewriteEngine On
    RewriteRule ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:19054/usr/local/apache/vhosts/%{SERVER_NAME}/$1 [P]
</VirtualHost>

vhosts directory contains directories with domain names that Apache will dynamically match to each request. All PHP files are then matched and their requests are forwarded to PHP FPM process listening at 127.0.0.1:19054.

This configuration works with further rewrite rules defined inside virtual hosts directories.



来源:https://stackoverflow.com/questions/18191546/0-is-not-replaced-by-server-name-when-used-with-apaches-proxypassmatch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!