CONTENT
  • CHANGES
Szukaj
counter

#top Nginx behind HAProxy


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

W niniejszej konfiguracji HAProxy odbiera połączenia przychodzące na port 80 i przekierowywuje je do Nginx na port 85:

Plik konfiguracyjny /etc/nginx/nginx.conf:
http {
[...]
    #The configuration always includes the predefined "combined" format:
    #log_format   combined   '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"';
    log_format   combinedpe '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"';
    log_format  vcombined   '$host $remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"';
    log_format  vcombinedpe '$host $remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"';

    set_real_ip_from  10.41.0.58/32;
    real_ip_header    X-Forwarded-For;
    #real_ip_recursive off;
[...]
}

Plik konfiguracyjny /etc/nginx/vhosts/cen06x64.xen.wbcd.pl.conf:
#
# cen06x64.xen.wbcd.pl
#
server {
    #limit_conn   myzone  10;
    listen       85;
    server_name  cen06x64.xen.wbcd.pl;
    #charset koi8-r;

    access_log  /var/log/nginx/cen06x64_xen_wbcd_pl.access.log  combinedpe;
    error_log  /var/log/nginx/cen06x64_xen_wbcd_pl.error.log  error;

    location / {
        root   /srv/nginx/vhosts/cen06x64.xen.wbcd.pl;
        index  index.html index.htm;
    }

    error_page  404              /404.html;
    location = /404.html {
        root   /srv/nginx/error;
    }

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /srv/nginx/error;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny  all;
    }
}

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 Nginx zamiast adresu serwera Proxy zapisywany był adres klienta łączącego się poprzez Proxy niezbędne jest skonfigurowanie dyrektyw set_real_ip_from określających adres IP serwera Proxy z który będzie wysyłał nagłówek X-Forwarded-For zawierający adres IP klienta oraz real_ip_header definującej nazwę nagłówka zawierającego adres IP klienta, a zmienna $remote_addr użyta w log_format będzie zawierała adres IP klienta, który będzie zapisywany w logach access serwera Nginx (Zobacz sekcję LogFormat).




Zmodyfikowany ostatnio: 2018/04/11 23:28:36 (7 lat temu), textsize: 33,2 kB, htmlsize: 4,88 kB

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