1

Expect result:

If I go to http://foo.local/index.php, file /var/www/html/foo/index.php will be executed.

It will be similar if I go to http://bar.local/index.php, /var/www/html/bar/index.php will be executed.

Here are my configurations:

<VirtualHost *:80>
    ServerAlias *.localhost
    VirtualDocumentRoot /var/www/html/%1/

    <IfModule proxy_module>
        #ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://localhost:9000/var/www/html/$1 (this  line works in normal virtualhost)
        ProxyRemoteMatch ^([^.]+).*/(.*\.php(/.*)?)$ fcgi://localhost:9000/var/www/html/$1/$2
    </IfModule>
</VirtualHost>

For now, this is working well for static files like .html. But it will print .php files instead of executing them.

Please advise, thank you.

PS: If I use mod_php instead of php-fpm, it would be easier. But for learning purpose, I really want to go the hard way.

1

Here is my own solution (use RewriteRule with [P] flag instead of ProxyPass):

<VirtualHost *:80>
    ServerAlias *.localhost
    VirtualDocumentRoot /var/www/html/%1/

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^([^.]+) [NC]
    RewriteRule ^/(.*\.php(/.*)?)$ fcgi://php:9000/var/www/html/%1/$1 [P]
    #<IfModule proxy_module>
        #ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://php:9000/var/www/html/$1
        #ProxyRemoteMatch ^([^.]+).*/(.*\.php(/.*)?)$ fcgi://php:9000/var/www/html/$1/$2
    #</IfModule>
</VirtualHost>

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.