facebook twitter hatena line email

「Linux/nginx/apache経由」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(mod_rpafのインストール)
(mod_remoteipをインストール)
行50: 行50:
 
> remoteip_module (shared) # となればインストールされてる
 
> remoteip_module (shared) # となればインストールされてる
 
</pre>
 
</pre>
 +
 +
===mod_remoteipの設定===
 
/etc/httpd/conf/httpd.confの下の方に以下追加
 
/etc/httpd/conf/httpd.confの下の方に以下追加
 
<pre>
 
<pre>
行56: 行58:
 
<IfModule remoteip_module>
 
<IfModule remoteip_module>
 
   RemoteIPHeader X-Forwarded-For
 
   RemoteIPHeader X-Forwarded-For
   RemoteIPInternalProxy 160.16.200.243
+
   RemoteIPInternalProxy [ここにnginxのサーバを入れる]
 
   LogFormat "%a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
 
   LogFormat "%a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
 
   LogFormat "%a %l %u %t \"%r\" %>s %b" common
 
   LogFormat "%a %l %u %t \"%r\" %>s %b" common

2025年7月26日 (土) 02:18時点における版

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のサーバを入れる]
  LogFormat "%a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
  LogFormat "%a %l %u %t \"%r\" %>s %b" common
</IfModule>

apache再起動

service httpd restart