0

I have a nginx/1.18.0 and php-fpm 7.4.19 (fpm-fcgi)

PHP code header('Content-Type: text/css',true) doesn't modify the header, the same for application/javascript or image/jpg, files are sent with content type text/html.

instead, these headers work header('Cache-Control': max-age..., header('Expires: ..

A workaround that works is adding this to the website nginx configuration: location = /my-file.php { add_header Content-Type text/css;

                    fastcgi_intercept_errors on;
                    fastcgi_index  index.php;
                    include        fastcgi_params;
                    fastcgi_param  SCRIPT_FILENAME  $request_filename;
                    fastcgi_param  PATH_INFO $fastcgi_path_info;
                    fastcgi_pass   php-fpm; 
        }

But this solution is not practical when in a WordPress site for example, there are a lot of php files that output css, javascript some of them even output different content types.

I don't have the problem overwriting the content-type header from PHP on a server with the same php-fpm 7.4.19 and Apache/2.4.46

Do you have any idea why I can't modify the Content-Type header from PHP ?

TeoD
  • 1

0 Answers0