Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 527
mattes Avatar asked Oct 21 '22 03:10

mattes


1 Answers

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.

like image 162
Jozef Izso Avatar answered Oct 24 '22 10:10

Jozef Izso