# Cloudflare Real-IP 通过 Apache 实现

**URL:** https://meta.discourse.org/t/cloudflare-real-ip-via-apache/113482
**Category:** Self-hosting
**Created:** [2019年四月4日 21:26 UTC](https://meta.discourse.org/t/cloudflare-real-ip-via-apache/113482 "2019-04-04T21:26:26Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![RyanGarber](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ryangarber/32/137479_2.png) [@RyanGarber](https://meta.discourse.org/u/RyanGarber)
#### Post date: [2019年四月5日 20:50 UTC](https://meta.discourse.org/t/cloudflare-real-ip-via-apache/113482/4 "2019-04-05T20:50:39Z")

</div>

I did some more testing and realized there were a few other problems. For one, request headers are not exposed by default in Apache variables, so you must use the `SetEnvIf` directive.

And finally, I changed the proxy to use sockets. When using a simple HTTP proxy, it would still use the old Cloudflare IP. I added the web.socketed template in addition to the cloudflare one, and rebuilt.

Final config:

```
SetEnvIf CF-Connecting-IP (.*) real_ip=$1
RequestHeader set X-Real-IP %{real_ip}e
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / unix:/var/discourse/shared/standalone/nginx.http.sock|http://127.0.0.1/
ProxyPassReverse / unix:/var/discourse/shared/standalone/nginx.http.sock|http://127.0.0.1/

```

And now it works 😄

 ![](https://global.discourse-cdn.com/meta/original/3X/2/e/2ef05a8c2e44b5ee22c04db95d4abc89c18e706c.png)

---

_[View the full topic](https://meta.discourse.org/t/cloudflare-real-ip-via-apache/113482)._
