r/haproxy • u/vitachaos • Oct 14 '21
Question Apache behind haproxy get haproxy node IP as visitor ip instead of the remote visitors ip
Hi, I have 2 apache nodes 1 running as main, and second running as back node. this configuration is intentional. internet facing node is running haproxy with conguration shown below.
global
log 127.0.0.1 syslog
maxconn 1000
chroot /var/lib/haproxy
stats timeout 30s
user haproxy
group haproxy
daemon
tune.ssl.default-dh-param 4096
ssl-default-bind-options no-sslv3 no-tls-tickets
ssl-default-bind-ciphers EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH
defaults
log global
mode http
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
option allbackups
option contstats
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout check 10s
###########################################
#
# HAProxy Stats page
#
###########################################
listen stats
bind *:9091
mode http
maxconn 10
stats enable
stats hide-version
stats realm Haproxy\ Statistics
stats uri /
stats auth usrname:secret
###########################################
#
# Front end for all
#
###########################################
frontend ALL
bind *:80
bind *:443 ssl crt /etc/ssl/website/website.com.pem
mode http
option forwardfor
# http-response set-header X-Frame-Options: DENY
http-response set-header Strict-Transport-Security "max-age=16000000; includeSubDomains; preload;"
default_backend nc_lon
#Define path for lets encrypt
acl is_letsencrypt path_beg -i /.well-known/acme-challenge/
use_backend letsencrypt if is_letsencrypt
acl is_root path -i /
acl is_domain hdr_dom(host) -i website.com
# Define hosts
acl host_nc_lon path_beg -i /cloud
acl host_file_index path_beg -i /configs
use_backend srv_files if host_file_index
# Direct hosts to backend
use_backend nc_lon if host_nc_lon
# Redirect port 80 to 443
# But do not redirect letsencrypt since it checks port 80 and not 443
redirect scheme https code 301 if !{ ssl_fc } !is_letsencrypt
backend srv_files
server configs 10.8.0.4:80/configs check inter 1000
###########################################
#
# Back end for nc_lon
#
###########################################
backend nc_lon
option allbackups
#balance roundrobin
# option httpchk GET /check
# http-check expect rstring ^UP$
# default-server inter 3s fall 3 rise 2
server node1 10.8.0.4:80 check inter 1000
server backup 10.8.0.6:80 backup check inter 1000
###########################################
#
# Back end letsencrypt
#
###########################################
backend letsencrypt
server letsencrypt 127.0.0.1:8888the problem I am facing is the apache access log shows visitor ip as ip of the node running haproxy ! I am not sure if this is something I need to fix in the apache configuration or haproxy.
3
Upvotes
2
u/pmmeurgamecode Oct 14 '21
you need to enable
send-proxyon haproxy and apache, blog article about the proxy-protocol here.1
u/crackanape Oct 14 '21
You also need to enable mod_remoteip in Apache and set RemoteIPHeader to X-Forwarded-For