Files
cloud-apache-container/configs/shared-vhost-template.tpl
jknapp 1490bde56e
Some checks failed
Cloud Apache Container / Build-and-Push (74) (push) Successful in 2m7s
Cloud Apache Container / Build-and-Push (80) (push) Successful in 1m59s
Cloud Apache Container / Build-and-Push (81) (push) Successful in 2m3s
Cloud Apache Container / Build-and-Push (82) (push) Successful in 2m26s
Cloud Apache Container / Build-and-Push (83) (push) Successful in 2m21s
Cloud Apache Container / Build-and-Push (84) (push) Successful in 1m51s
Cloud Apache Container / Build-FPM-Images (74) (push) Has been cancelled
Cloud Apache Container / Build-FPM-Images (80) (push) Has been cancelled
Cloud Apache Container / Build-FPM-Images (81) (push) Has been cancelled
Cloud Apache Container / Build-FPM-Images (82) (push) Has been cancelled
Cloud Apache Container / Build-FPM-Images (83) (push) Has been cancelled
Cloud Apache Container / Build-FPM-Images (84) (push) Has been cancelled
Cloud Apache Container / Build-FPM-Images (85) (push) Has been cancelled
Cloud Apache Container / Build-Shared-httpd (push) Has been cancelled
Cloud Apache Container / Build-and-Push (85) (push) Has been cancelled
Switch shared vhost from SetHandler to ProxyPassMatch for PHP-FPM
SetHandler + ProxyFCGISetEnvIf doesn't work for path remapping because
reqenv('SCRIPT_FILENAME') is empty when the directive evaluates with
the SetHandler approach.

ProxyPassMatch directly maps .php URLs to the FPM container's filesystem
path, bypassing the SCRIPT_FILENAME rewrite issue entirely:
  ^/(.*\.php(/.*)?)$ -> fcgi://fpm:9000/home/{user}/public_html/$1

Static assets (CSS, JS, images) bypass the proxy since they don't match
\.php and are served directly by Apache from the read-only mount.

Tested and confirmed working on live site with WordPress (including
pretty URLs via .htaccess mod_rewrite).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 12:50:54 -07:00

42 lines
1.4 KiB
Smarty

<Directory "/mnt/users/~~user~~/~~domain~~">
AllowOverride None
Require all granted
</Directory>
<Directory "/mnt/users/~~user~~/~~domain~~/public_html">
Options All MultiViews
AllowOverride All
Require all granted
</Directory>
<VirtualHost *:80>
ServerName "~~domain~~"
~~alias_block~~
DocumentRoot "/mnt/users/~~user~~/~~domain~~/public_html"
RewriteEngine on
RewriteCond %{SERVER_NAME} =~~domain~~
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName "~~domain~~"
~~alias_block~~
DocumentRoot "/mnt/users/~~user~~/~~domain~~/public_html"
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
# Proxy PHP requests to FPM with the correct filesystem path.
# Apache serves static files directly from /mnt/users/ (read-only mount),
# but PHP-FPM has files at /home/{user}/public_html/ (its own mount).
# ProxyPassMatch maps .php URLs directly to the FPM container's path.
ProxyPassMatch "^/(.*\.php(/.*)?)$" "fcgi://~~fpm_host~~:~~fpm_port~~/home/~~user~~/public_html/$1"
DirectoryIndex index.php index.html index.htm
ErrorLog "/var/log/httpd/~~domain~~-error.log"
CustomLog "/var/log/httpd/~~domain~~-access.log" combined
</VirtualHost>
</IfModule>