Score:0

Apache Header set missing in server response when php-fpm is active, shown when php-fpm is inactive

us flag

Problem: When php-fpm is enabled, cors headers set in .htaccess are not shown in response. When php-fpm is disabled, cors headers are shown in the response.

Current setup:

Server:

  • Ubuntu 20.04 on Aliyun cloud (Shanghai region)
  • Apache 2.4, headers module enabled
  • php 7.4 with php7.4-fpm enabled.

In .htaccess I've set:

Header always set Access-Control-Allow-Origin "*"
Header always set Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header always set Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"

In vhost config I have set:

<VirtualHost *:443>
    ServerName api.test.com
    DocumentRoot /path/to/www
    ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/path/to/www/$1
    ErrorLog /path/to/log
    CustomLog /path/to/log
    <Directory /path/to/www/ >
        Options Indexes FollowSymlinks Includes execCGI
        AllowOverride All
        Require all granted
    </Directory>
    SSLCErtificateFile /path/to/pem
    SSLCertificateKeyFile /path/to/key
    Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>

If I comment the line # ProxyPassMatch .... and restart apache and php-fpm, headers for cors set in .htaccess above are shown as expected.

However if php-fpm is set in vhost, after restart apache and php-fpm, headers listed in .htaccess are not provided in response.

Response in both cases (with and without php-fpm) is still valid, code 200, with some echo text I've set as output.

No errors logged.

I've never encountered this issue on AWS instances, neither when developing in my local environment.

Can anyone point me how php-fpm affects response headers, am I doing something wrong in vhost / htaccess or missing .ini settings?

Diogo Braga avatar
cn flag
Did you found a solution?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.