説明†nginxをロードバランサーとして活用するための基本的な手順です。 設定†# cd /etc/nginx/ # cp -p nginx.conf nginx.conf.`date +%Y%m%d` # vi nginx.conf --- http { #ロードバランサー設定 upstream backend1 { <-- backendの箇所は任意。proxy_pathで指定する。 server 192.168.100.100:80; server 192.168.100.101:80; } --- # cd conf.d # cp -p default.conf default.conf.`date +%Y%m%d` # vi default.conf --- server{ proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # クライアントの IP アドレス proxy_set_header X-Forwarded-Host $host; # オリジナルのホスト名。クライアントが Host リクエストヘッダで渡す。 proxy_set_header X-Forwarded-Server $host; # プロキシサーバのホスト名 proxy_set_header X-Real-IP $remote_addr; location / { #root /usr/share/nginx/html; #index index.html index.htm; proxy_pass http://backend1; } # service nginx configtest # servcie nginx reload バックエンドのサーバーのapacheのログ設定†# cd /etc/httpd/conf # cp -p httpd.conf httpd.conf.`date +%Y%m%d` # vi httpd.conf --- #LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %{X-Forwarded-For}i" combined --- # service httpd configtest # service httpd graceful バックエンドのサーバーのnginxのログ設定†# vi /etc/nginx/conf.d/realip.conf set_real_ip_from (リバースプロキシの IP アドレス); real_ip_header X-Forwarded-For; # service nginx reload |