The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

HAProxy Proxy and X-Forward-For IP in Apache Logs

Discussion in 'General Discussion' started by Chris Rose, Oct 28, 2015.

  1. Chris Rose

    Chris Rose Member

    Joined:
    Aug 4, 2015
    Messages:
    17
    Likes Received:
    4
    Trophy Points:
    3
    Location:
    United kingdom
    cPanel Access Level:
    Root Administrator
    Good Evening!

    I have a WHM server (11.50) running on CentOS 7 that hosts multiple sites. One of the sites/accounts requires a reverse proxy to be set up in front of it to balance traffic between the account and a backup server.

    I have got an HAProxy server acting as the reverse proxy/load balancer to the cPanel account. However, when I view the RAW Access Logs or the Latest visitors area within the account cPanel. All visits are appearing/originating from the load balancer/reverse proxy IP. This is obviously an issue as I want to be able to monitor IP addresses correctly (for reporting/security purposes).

    HAProxy is properly configured and is sending the X-Forwarded-For header in all requests.

    I have found many posts online (both on here and through Google) saying that I should edit the httpd.conf file within the /etc/httpd/conf/ folder within CentOS7 to comment out the existing LogFormat line and to insert a new one with the relevant {X-Forwarded-For} tag inserted. I have done this and the following line shows what is in my httpd.conf file:

    LogFormat "%h %{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

    After editing the file and restarting Apache via the restart services area on WHM. and Trying again. the visits are still not being recorded in the logs.

    Could someone explain what I am doing wrong or if I should be doing this in a different area on the server?

    Also is it possible to just have this log setting for that particular account and have remaining accounts as standard log files?

    Many Thanks for any help you can provide.

    Kind Regards,
    Chris
     
  2. Chris Rose

    Chris Rose Member

    Joined:
    Aug 4, 2015
    Messages:
    17
    Likes Received:
    4
    Trophy Points:
    3
    Location:
    United kingdom
    cPanel Access Level:
    Root Administrator
    Ok so I finally sorted this.. if anyone is interested, I did the following:

    From within WHM, I went to:
    Home » Service Configuration » Apache Configuration » Include Editor

    I then added the following line into the Post VirtualHost Include box:
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%{X-Forwarded-For}i\"" combined

    Clicked "Update" and then restarted Apache. Log files are now showing as they should :)

    Chris
     
    #2 Chris Rose, Nov 2, 2015
    Last edited by a moderator: Nov 3, 2015
  3. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
Loading...

Share This Page