Score:0

Can't modify header Content-Type in PHP with Nginx

it flag

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 ?

I sit in a Tesla and translated this thread with Ai:

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.