A
A
Alexey2016-05-29 12:13:38
PHP
Alexey, 2016-05-29 12:13:38

Why empty Content-Type in nginx, php-fpm bundle?

Good afternoon!
Faced a problem with getting HTTP headers.
I am using nginx and php-fpm. The task was to get an additional header and check it.
Used the alternative getallheaders function:

if (!function_exists('getallheaders'))
{
    function getallheaders()
    {
        $headers = '';
        foreach ($_SERVER as $name => $value)
        {
            if (substr($name, 0, 5) == 'HTTP_')
            {
                $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
            }
        }
        return $headers;
    }
}

Variables with the HTTP_ key from the $_SERVER variable are written to it.
In the Nginx config, I specified:
location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass    127.0.0.1:9000;
        try_files  $uri =404;

        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param   CONTENT_TYPE    $content_type;
        fastcgi_param   CONTENT_LENGTH  $content_length;

        fastcgi_param   HTTP_HOST               $host;
        fastcgi_param   HTTP_CONTENT_TYPE       $content_type;
        fastcgi_param   HTTP_CONTENT_HMAC       $http_content_hmac;

        access_log  /var/log/nginx/postdata.log  main_post;
}

I can't figure out why the $_SERVER[CONTENT_TYPE] variable is passing an empty value?
The question is also of interest: how to specify an additional parameter in the config, in my example it is Content-HMAC. For output in the logs, the variable is specified "http_content_hmac"
Thank you in advance for your help!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question