CONTENT
  • CHANGES
Szukaj
counter

#top Apache behind HAProxy


Zobacz także Apache behind HAProxy dla: HAProxy (HAProxy)

W niniejszej konfiguracji HAProxy odbiera połączenia przychodzące na port 80 i w zależności od rodzaju żądania
przekierowywuje je do Apache prefork na port 81 lub Apache worker na port 82:

Plik konfiguracyjny /etc/httpd/httpd.conf:
#
# PidFile: The file in which the server should record its process
# identification number when it starts.  Note the PIDFILE variable in
# /etc/sysconfig/httpd must be set appropriately if this location is
# changed.
#
<IfModule prefork.c>
PidFile /var/run/httpd/httpd1.pid
</IfModule>
<IfModule worker.c>
PidFile /var/run/httpd/httpd2.pid
</IfModule>

[...]

#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, in addition to the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses (0.0.0.0)
#
#Listen 12.34.56.78:80
<IfModule prefork.c>
Listen 81
</IfModule>
<IfModule worker.c>
Listen 82
</IfModule>

Plik konfiguracyjny /etc/httpd/httpd.conf:
#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
#
SetEnvIf Remote_Addr "^(.*)$" ENVRemote=$1
SetEnvIf X-Forwarded-For "(::ffff:)?([0-9][0-9\.]*|[0-9a-f][0-9a-f:]*)$" ENVRemote=$2
LogFormat "%{ENVRemote}e %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combinedpe
LogFormat "%V %{ENVRemote}e %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" vcombinedpe

[...]

#
# Use name-based virtual hosting.
#
<IfModule prefork.c>
NameVirtualHost *:81
</IfModule>
<IfModule worker.c>
NameVirtualHost *:82
</IfModule>

Plik konfiguracyjny /etc/httpd/vhosts/01-cen06x64.xen.wbcd.pl.conf:
<VirtualHost *:81 *:82>
ServerName  cen06x64
ServerAlias cen06x64.xen.wbcd.pl
ServerAlias static.cen06x64.xen.wbcd.pl
ServerAdmin admin@cen06x64.xen.wbcd.pl
ServerPath   /srv/http/vhosts/cen06x64.xen.wbcd.pl
DocumentRoot /srv/http/vhosts/cen06x64.xen.wbcd.pl/
ErrorLog  /var/log/httpd/cen06x64_xen_wbcd_pl-error.log
CustomLog /var/log/httpd/cen06x64_xen_wbcd_pl-access.log combinedpe
</VirtualHost>

Zgodnie z RFC 7239 - Forwarded HTTP Header Field
A proxy server that wants to add a new "Forwarded" header field value
can either append it to the last existing "Forwarded" header field
after a comma separator or add a new field at the end of the header block.
oraz dokumentacją na stronie X-Forwarded-For (mozilla.org)
Syntax
X-Forwarded-For: <client>, <proxy1>, <proxy2>
adres IP klienta jest pierwszym adresem na liście w nagłówku HTTP X-Forwarded-For. Natomiast adres IP klienta łączącego się do serwera WWW jest ostatnim adresem IP na liście w nagłówku HTTP X-Forwarded-For dodanym przez serwer HAProxy, który przekazuje odebrane żądanie HTTP do serwera WWW i ten adres zostanie zapisany w logach access serwera.

Aby w logach access serwera Apache zamiast adresu serwera Proxy zapisywany był adres klienta łączącego się poprzez Proxy niezbędne jest zastosowanie dyrektyw warunkowych SetEnvIf ustawiających adres IP klienta w zmiennych środowiskowych, a następnie w dyrektywie LogFormat zamiana Format String zawierającego Remote host na przygotowaną wcześniej zmienną środowiskową (Zobacz sekcję LogFormat).




Zmodyfikowany ostatnio: 2018/04/11 23:28:36 (7 lat temu), textsize: 106 kB, htmlsize: 7,04 kB

Zapraszam do komentowania, zgłaszania sugestii, propozycji, własnych przykładów, ...
Dodaj komentarzKomentarze użytkowników