{"id":49042,"date":"2020-05-25T09:53:56","date_gmt":"2020-05-25T07:53:56","guid":{"rendered":"https:\/\/mamchenkov.net\/wordpress\/?p=49042"},"modified":"2020-05-25T09:53:56","modified_gmt":"2020-05-25T07:53:56","slug":"send-additional-http-headers-to-nginxs-fastcgi","status":"publish","type":"post","link":"https:\/\/mamchenkov.net\/wordpress\/2020\/05\/25\/send-additional-http-headers-to-nginxs-fastcgi\/","title":{"rendered":"Send additional HTTP headers to Nginx&#8217;s FastCGI"},"content":{"rendered":"<!-- google_ad_section_start -->\n<p>It&#8217;s not that often that I come across a useful, but undocumented feature in a major software application.\u00a0 It happened recently, so I&#8217;ll document it here just for the future self.<\/p>\n<p>For a particular setup, I had to send additional HTTP headers (let&#8217;s use X-GEOIP for this example) to the PHP-FPM, which was configured as a FastCGI backend in Nginx web server.\u00a0 <a href=\"https:\/\/stackoverflow.com\/questions\/9464805\/send-additional-header-to-fastcgi-backend-with-nginx\">This StackOverflow thread<\/a> suggested several solutions, but <a href=\"https:\/\/stackoverflow.com\/a\/47221683\/151647\">this one<\/a> was the easiest and worked like a charm: use Nginx&#8217;s <em>fastcgi_param<\/em> directive AND prefix your variables with <em>HTTP_<\/em>.\u00a0 For example:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nlocation ~ \\.php$ {\r\n  fastcgi_param HTTP_X_GEOIP $geoip;\r\n  ... other settings\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<!-- google_ad_section_end -->\n","protected":false},"excerpt":{"rendered":"<!-- google_ad_section_start -->\n<p>It&#8217;s not that often that I come across a useful, but undocumented feature in a major software application.\u00a0 It happened recently, so I&#8217;ll document it here just for the future self. For a particular setup, I had to send additional HTTP headers (let&#8217;s use X-GEOIP for this example) to the PHP-FPM, which was configured as &hellip; <a href=\"https:\/\/mamchenkov.net\/wordpress\/2020\/05\/25\/send-additional-http-headers-to-nginxs-fastcgi\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Send additional HTTP headers to Nginx&#8217;s FastCGI<\/span><\/a><\/p>\n<!-- google_ad_section_end -->\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_links_to":"","_links_to_target":""},"categories":[1,6,133,62,1334],"tags":[3164,38,1330,2289],"keyring_services":[],"class_list":["post-49042","post","type-post","status-publish","format-standard","hentry","category-general","category-linux","category-sysadmin","category-technology","category-web-work","tag-nginx","tag-php","tag-web-development","tag-web-hosting"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":24603,"url":"https:\/\/mamchenkov.net\/wordpress\/2015\/08\/19\/custom-single-sign-on-with-nginx-and-auth-request-module\/","url_meta":{"origin":49042,"position":0},"title":"Custom Single Sign-On with Nginx and Auth Request Module","author":"Leonid Mamchenkov","date":"August 19, 2015","format":false,"excerpt":"In a recent project I crashed into a wall. \u00a0At least for a couple of days that is. \u00a0The requirement was to integrate the Request Tracker (aka RT) installation on CentOS 7 server with Nginx to\u00a0a client's company single sign-on solution. \u00a0Which wasn't LDAP. \u00a0Or Active Directory. \u00a0Or anything standard\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26306,"url":"https:\/\/mamchenkov.net\/wordpress\/2016\/08\/04\/504-gateway-timeout-error-on-nginx-fastcgi-php-fpm\/","url_meta":{"origin":49042,"position":1},"title":"504 Gateway Timeout error on Nginx + FastCGI (php-fpm)","author":"Leonid Mamchenkov","date":"August 4, 2016","format":false,"excerpt":"\"504 Gateway Timeout\" error is a very common issue when using Nginx with PHP-FPM. \u00a0Usually, that means that it took PHP-FPM longer to generate the response, than Nginx was willing to wait for. \u00a0A few possible reasons for this are: Nginx timeout configuration uses very small values (expecting the responses\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"504","src":"https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2016\/08\/504-500x385.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":27865,"url":"https:\/\/mamchenkov.net\/wordpress\/2017\/08\/21\/using-php-fpm-as-a-simple-built-in-async-queue\/","url_meta":{"origin":49042,"position":2},"title":"Using php-fpm as a simple built-in async queue","author":"Leonid Mamchenkov","date":"August 21, 2017","format":false,"excerpt":"Here's an interesting solution for a poor man's asynchronous queue using PHP-FPM: PHP-FPM already acts as a queue for Nginx\/Apache FastCGI clients. While your web-request is running you can just send another FastCGI request to the same PHP-FPM socket asynchronously and non-blocking. This request is immediately executed in another php-fpm\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":18031,"url":"https:\/\/mamchenkov.net\/wordpress\/2013\/04\/16\/apache2-vs-nginx-for-php-application\/","url_meta":{"origin":49042,"position":3},"title":"Apache2 vs Nginx for PHP application","author":"Leonid Mamchenkov","date":"April 16, 2013","format":"link","excerpt":"Apache2 vs Nginx for PHP application The conclusion is that it doesn\u2019t matter which server you are going to chose. The real performance wins are purely on PHP side. Using an accelerator with caching can multiply the number of requests your infrastructure can maintain.","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":22700,"url":"https:\/\/mamchenkov.net\/wordpress\/2014\/10\/22\/url-rewriting-in-built-in-web-server-of-php\/","url_meta":{"origin":49042,"position":4},"title":"URL rewriting in built-in web server of PHP","author":"Leonid Mamchenkov","date":"October 22, 2014","format":false,"excerpt":"PHP comes with a handy for development built-in web server. \u00a0However, most web projects have friendly URLs these days which are either Apache (mod_rewrite) or Nginx specific configuration. \u00a0This almost renders built-in PHP web server useless. \u00a0Unless you provide a PHP-based routing, like so: [code lang=\"php\"] $request_uri = __DIR__ .\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":48892,"url":"https:\/\/mamchenkov.net\/wordpress\/2020\/05\/13\/caddy-the-ultimate-server-with-automatic-https\/","url_meta":{"origin":49042,"position":5},"title":"Caddy &#8211; The Ultimate Server with Automatic HTTPS","author":"Leonid Mamchenkov","date":"May 13, 2020","format":false,"excerpt":"Great things are easy to get used to.\u00a0 When something works the way you want it, and does so for a long a time, it is inevitable that one day you'll stop thinking about it altogether and accept it as a given. Apache was a great web server, until Nginx\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"Caddy web server","src":"https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2020\/05\/caddy-500x293.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts\/49042","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/comments?post=49042"}],"version-history":[{"count":0,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts\/49042\/revisions"}],"wp:attachment":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/media?parent=49042"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/categories?post=49042"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/tags?post=49042"},{"taxonomy":"keyring_services","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/keyring_services?post=49042"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}