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 Answer 1

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> 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.