I'm attempting to "rebuild" an infrastructure for the development team in my company using Docker. I accomplished this about 1 year ago, and now I'm working on refactoring and rewriting it to better match our production environment. I've successfully translated most of the apache directives to nginx. As a result, we're using nginx as a proxy and web server in the development environment. However, in our production setup, we use apache as the web server and nginx as a reverse proxy. This is the reason for my current effort to make the setup align.
I'm building a new project and separated apache, php-fpm, and nginx into different containers. This is where the issue arises. The Apache + FCGI configurations keep generating the errors listed below:
This should be the reponse body, but for some reason it's appearing as a response header
[proxy_fcgi:error] malformed header from script 'index.php': Bad header: {"success":true,"token":"1F535, referer: http://localhost/
[proxy_fcgi:error] AH01070: Error parsing script headers, referer: http://localhost/
[proxy_fcgi:error] (22)Invalid argument: [client 172.19.0.1:42216] AH01075: Error dispatching request to : , referer: http://localhost/
This is my current apache settings
ServerName localhost
LoadModule deflate_module /usr/local/apache2/modules/mod_deflate.so
LoadModule proxy_module /usr/local/apache2/modules/mod_proxy.so
LoadModule proxy_fcgi_module /usr/local/apache2/modules/mod_proxy_fcgi.so
<VirtualHost *:80>
<IfModule proxy_module>
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://php:9000/var/www/html/company/public/$1
</IfModule>
<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
</IfModule>
DocumentRoot /var/www/html/company/public
<Directory /var/www/html/company/public>
DirectoryIndex index.php
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
# Send apache logs to stdout and stderr
CustomLog /proc/self/fd/1 common
ErrorLog /proc/self/fd/2
</VirtualHost>
Versions
APACHE_VERSION=2.4.57-alpine
PHP_VERSION=7.4.33-fpm-alpine3.16
NGINX_VERSION=1.25.1-alpine3.17
The PHP application is very old, we're using ZendFramework v1
I attempted to modify the ProxyRules, but that approach proved ineffective. When I combine PHP and Apache within the same container, the setup functions correctly, as it bypasses the need for the fastcgi layer. I explored the Apache documentation and various answers on Stack Overflow, but unfortunately, none of them appeared to provide a solution.