「Linux/nginx/apache経由」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→apacheに引き渡す際のreverse_proxy設定) |
(→mod_remoteipの設定) |
||
(同じ利用者による、間の5版が非表示) | |||
行20: | 行20: | ||
listen 8090; | listen 8090; | ||
server_name example.localhost; | server_name example.localhost; | ||
− | location ~* \.(jpg|gif|png|swf|css|js|inc|ico|pdf|flv|gz|woff|html|htm|txt|xml)$ { | + | location ~* \.(jpg|jpeg|gif|png|swf|css|js|inc|ico|pdf|flv|gz|woff|html|htm|txt|xml)$ { |
root /var/www/zend/example/public; | root /var/www/zend/example/public; | ||
index index.html; | index index.html; | ||
行43: | 行43: | ||
・・略・・ | ・・略・・ | ||
− | == | + | ==apache側で、nginxからのクライアントipを受ける方法== |
− | + | ===mod_remoteipをインストール=== | |
− | + | <pre> | |
− | + | # mod_remoteipのインストール確認 | |
− | + | $ httpd -M 2>/dev/null | grep remoteip | |
− | + | > remoteip_module (shared) # となればインストールされてる | |
− | + | </pre> | |
− | + | ||
− | + | ===mod_remoteipの設定=== | |
− | + | /etc/httpd/conf/httpd.confの下の方に以下追加 | |
− | + | <pre> | |
− | + | LoadModule remoteip_module modules/mod_remoteip.so | |
− | + | ||
+ | <IfModule remoteip_module> | ||
+ | RemoteIPHeader X-Forwarded-For | ||
+ | RemoteIPInternalProxy [ここにnginxのproxyサーバipを入れる] | ||
+ | LogFormat "%a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined | ||
+ | LogFormat "%a %l %u %t \"%r\" %>s %b" common | ||
+ | </IfModule> | ||
+ | </pre> | ||
+ | |||
+ | %aの部分がnginxのproxyのipから、クライアントipに差し替わる | ||
+ | |||
+ | apache再起動 | ||
+ | service httpd restart |
2025年7月26日 (土) 02:21時点における最新版
目次
apacheに引き渡す際のreverse_proxy設定
apacheでなく別のnginxに引き渡したい時も同様に使える(cookieもひき注がれる)
- /etc/nginx/conf.d/example.conf
server { listen 8090; server_name example.localhost; location / { proxy_pass http://127.0.0.1:80; 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; } }
動的処理はapacheに渡し、静的ファイルはapacheに渡さない場合の設定
server { listen 8090; server_name example.localhost; location ~* \.(jpg|jpeg|gif|png|swf|css|js|inc|ico|pdf|flv|gz|woff|html|htm|txt|xml)$ { root /var/www/zend/example/public; index index.html; ssi on; access_log off; break; } location / { ・・略・・
正規表現の最後に$が付いているが.png?v=20150101などの画像でもhitする
apache側port変更設定
- /etc/httpd/conf/httpd.conf
Listen 80 Listen 8080 NameVirtualHost *:80 NameVirtualHost *:8080
- /etc/httpd/conf/extra/example.conf
<VirtualHost *:8080> ・・略・・
apache側で、nginxからのクライアントipを受ける方法
mod_remoteipをインストール
# mod_remoteipのインストール確認 $ httpd -M 2>/dev/null | grep remoteip > remoteip_module (shared) # となればインストールされてる
mod_remoteipの設定
/etc/httpd/conf/httpd.confの下の方に以下追加
LoadModule remoteip_module modules/mod_remoteip.so <IfModule remoteip_module> RemoteIPHeader X-Forwarded-For RemoteIPInternalProxy [ここにnginxのproxyサーバipを入れる] LogFormat "%a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%a %l %u %t \"%r\" %>s %b" common </IfModule>
%aの部分がnginxのproxyのipから、クライアントipに差し替わる
apache再起動
service httpd restart