※こちらは旧サイトです(新サイトはこちら)
Nginxをリバースプロキシに、DockerのApache(2.4)コンテナでmod_remoteipを使ってアクセス元IPを取得した時のメモ。
// httpディレクティブに追記
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
server {
listen 80;
server_name [コンテナに流すドメイン];
// serverディレクティブに追記
location / {
proxy_pass http://[コンテナのIP]:[コンテナのhttpポート];
break;
}
}
$ sudo systemctl restart nginx
// VirtualHostディレクティブに追記
<IfModule remoteip_module>
RemoteIPHeader X-Forwarded-For
RemoteIPInternalProxy 127.0.0.1
RemoteIPInternalProxy [ホスト側のIP]
</IfModule>
// LogFormatに「%a」追加
LogFormat "%h %a %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %a %l %u %t \"%r\" %>s %O" common
$ sudo a2enmod remoteip
$ sudo systemctl restart apache2