[wp-trac] Re: [WordPress Trac] #9235: Extract real IP behind a load balancer

WordPress Trac wp-trac at lists.automattic.com
Thu Jun 11 17:47:29 GMT 2009


#9235: Extract real IP behind a load balancer
-------------------------------+--------------------------------------------
 Reporter:  Denis-de-Bernardy  |       Owner:  Denis-de-Bernardy
     Type:  enhancement        |      Status:  accepted         
 Priority:  normal             |   Milestone:  2.9              
Component:  Optimization       |     Version:  2.7              
 Severity:  normal             |    Keywords:  needs-patch early
-------------------------------+--------------------------------------------

Comment(by robertaccettura):

 I've gotten to deal with WordPress behind a CDN or reverse proxy a few
 times now.  From what I've seen there are at least a dozen different HTTP
 headers that can be used for the origin/source IP.  WordPress can't "out
 of the box" handle everyone's situation perfectly, so it should be made
 easy to adjust:

 The most flexible would be to switch to a get_ip() or wp_get_ip()
 function, then let users be able to override it with their own by creating
 a plugin:

 {{{
 function get_ip(){
   return $_SERVER['X-REAL-IP'];
 }
 }}}

 Though not sure if that would happen early enough to be useful for init.

 The other option is to leave a mapping option in wp-config.php with the
 default and let users change if needed.  Something like:

 {{{
 // If your server sits behind a CDN or proxy you may need to adjust this
 $real_ip = $_SERVER['REMOTE_ADDR']

 }}}

 The easiest fix I've seen right now is to simply overwrite
 $_SERVER['REMOTE_ADDR'] via wp-config.php, as REMOTE_ADDR is rarely if
 ever useful in this situation.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/9235#comment:12>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list