{"id":8512,"date":"2024-06-06T06:45:33","date_gmt":"2024-06-06T06:45:33","guid":{"rendered":"https:\/\/www.infinitivehost.com\/knowledge-base\/?p=8512"},"modified":"2024-06-06T06:45:35","modified_gmt":"2024-06-06T06:45:35","slug":"set-http_cf_connecting_ip-in-apache-server-config","status":"publish","type":"post","link":"https:\/\/www.infinitivehost.com\/knowledge-base\/set-http_cf_connecting_ip-in-apache-server-config\/","title":{"rendered":"Set HTTP_CF_CONNECTING_IP in Apache Server Config"},"content":{"rendered":"<div class='epvc-post-count'><span class='epvc-eye'><\/span>  <span class=\"epvc-count\"> 2,441<\/span><span class='epvc-label'> Views<\/span><\/div>\n<p>Setting the <code>HTTP_CF_CONNECTING_IP<\/code> header in an Apache HTTP server configuration involves using the <code>mod_headers<\/code> module to set or modify the header value. The <code>HTTP_CF_CONNECTING_IP<\/code> header is typically used with Cloudflare to pass the original client IP address to your server.<\/p>\n\n\n\n<p>Here\u2019s how you can configure it:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Enable the <code>mod_headers<\/code> Module:<\/strong><br>Ensure that the <code>mod_headers<\/code> module is enabled. You can enable it by running the following command:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code has-vivid-red-color has-text-color has-link-color wp-elements-98f8a1ec080167f6ec36e11e09f48abb\"><code>   <code>sudo a2enmod headers<\/code><\/code><\/pre>\n\n\n\n<p>Then, restart Apache to apply the changes:<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-red-color has-text-color has-link-color wp-elements-7e533dbdd29a14ce069e069c42ceb8d5\"><code>   <code>sudo systemctl restart apache2<\/code><\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\">\n<li><strong>Configure the Header in Your Apache Configuration File:<\/strong><br>You need to add the configuration to your Apache virtual host configuration file, which is usually located in <code>\/etc\/apache2\/sites-available\/<\/code> for Debian-based distributions or <code>\/etc\/httpd\/conf.d\/<\/code> for Red Hat-based distributions. Open your virtual host configuration file, for example:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code has-vivid-red-color has-text-color has-link-color wp-elements-f2ed4856857ca507c745a2080bc80d05\"><code>   <code>sudo nano \/etc\/apache2\/sites-available\/000-default.conf<\/code><\/code><\/pre>\n\n\n\n<p>Add the following lines inside the <code>&lt;VirtualHost&gt;<\/code> block:<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-red-color has-text-color has-link-color wp-elements-c4f6ae77bffc6a183389d0d12f141a2b\"><code>   <code>&lt;VirtualHost *:80>\n       ServerName yourdomain.com\n\n       # Other configurations...\n\n       # Set HTTP_CF_CONNECTING_IP header\n       &lt;IfModule mod_headers.c>\n           RequestHeader set HTTP_CF_CONNECTING_IP \"%{HTTP:X-Forwarded-For}e\"\n       &lt;\/IfModule>\n\n       # Other configurations...\n   &lt;\/VirtualHost><\/code><\/code><\/pre>\n\n\n\n<p>If you are using HTTPS, make sure to update the configuration in the corresponding SSL virtual host file, typically named something like <code>default-ssl.conf<\/code>.<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"3\">\n<li><strong>Restart Apache:<\/strong><br>After making these changes, restart Apache to apply the new configuration:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code has-vivid-red-color has-text-color has-link-color wp-elements-7e533dbdd29a14ce069e069c42ceb8d5\"><code>   <code>sudo systemctl restart apache2<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Explanation:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>RequestHeader set:<\/strong> This directive is used to set the value of the <code>HTTP_CF_CONNECTING_IP<\/code> header.<\/li>\n\n\n\n<li><strong>&#8220;%{HTTP:X-Forwarded-For}e&#8221;:<\/strong> This extracts the <code>X-Forwarded-For<\/code> header, which is set by Cloudflare and contains the original client IP address.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Example with SSL:<\/h3>\n\n\n\n<p>If you are using HTTPS, you should update your SSL virtual host configuration file as well, for example:<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-red-color has-text-color has-link-color wp-elements-f79cc062d974e8953e3f0941de60c35f\"><code><code>sudo nano \/etc\/apache2\/sites-available\/default-ssl.conf<\/code><\/code><\/pre>\n\n\n\n<p>And add:<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-red-color has-text-color has-link-color wp-elements-74d6b54b173160c79bdbc312bbbacd29\"><code><code>&lt;VirtualHost *:443>\n    ServerName yourdomain.com\n\n    # Other configurations...\n\n    # Set HTTP_CF_CONNECTING_IP header\n    &lt;IfModule mod_headers.c>\n        RequestHeader set HTTP_CF_CONNECTING_IP \"%{HTTP:X-Forwarded-For}e\"\n    &lt;\/IfModule>\n\n    # Other configurations...\n&lt;\/VirtualHost><\/code><\/code><\/pre>\n\n\n\n<p>After making these changes, restart Apache again:<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-red-color has-text-color has-link-color wp-elements-f5d25c8a0674b49825b8b94ea0d57df3\"><code><code>sudo systemctl restart apache2<\/code><\/code><\/pre>\n\n\n\n<p>By following these steps, you can set the <code>HTTP_CF_CONNECTING_IP<\/code> header in your Apache HTTP server configuration, allowing you to correctly pass and use the original client IP address provided by Cloudflare.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>2,441 Views Setting the HTTP_CF_CONNECTING_IP header in an Apache HTTP server configuration involves using the mod_headers module to set or modify the header value. The HTTP_CF_CONNECTING_IP header is typically used with Cloudflare to pass the original client IP address to your server. Here\u2019s how you can configure it: Then, restart Apache to apply the changes: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[73],"tags":[],"class_list":["post-8512","post","type-post","status-publish","format-standard","hentry","category-cloudflare-cdn"],"_links":{"self":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/8512","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/comments?post=8512"}],"version-history":[{"count":1,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/8512\/revisions"}],"predecessor-version":[{"id":8513,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/8512\/revisions\/8513"}],"wp:attachment":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/media?parent=8512"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/categories?post=8512"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/tags?post=8512"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}