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?