0

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.

lonen
  • 1

1 Answers1

0

After spending a long time trying to fix this error, going back and forth for almost a year, I finally identified the issue. We had some Ajax method calls from our interface, and for some reason, someone had split the charset headers into new lines, resulting in something like this:

header('Content-Type: application/json;');
header('charset=ISO-8859-1');

Once I figured this out, I simply removed the new line and added the charset to the content type header.

header('Content-Type: application/json; charset=ISO-8859-1');

I also had another error from Zend returning "Cannot send headers; headers already sent" in Zend?" If your encounter something like this its probably due to some spacing or line breaks and the start/end of the php file.

How to fix "Cannot send headers; headers already sent" in Zend?

lonen
  • 1