LoginSignup
37
33

More than 5 years have passed since last update.

Apacheを用いたReverseProxyでのProxy Error(502)について

Last updated at Posted at 2015-02-28

リバースプロキシサーバへアクセス後、しばらく時間を置き、再度アクセス(ブラウザの更新ボタン押下)すると502エラーが表示される。
アドレスバーに再度URLを入力し、アクセスすると問題なくページが表示される。

Proxy Error 発生時の状況

事象発生環境

Reverse Proxy Server: CentOS 6.5 / httpd.x86_64 2.2.15-31.el6.centos
Backend Server: Windows Server 2008 R2 / IIS 7
Browser: Windows 8.1 / Internet Explorer 11

Apache 設定

# cat /etc/httpd/conf.d/proxy.conf
<Location /iis>
</Location>

ProxyPass /iis http://172.31.12.130/
ProxyPassReverse /iis http://172.31.12.130/

Proxy Error (502) Internet Explorer 11

502proxyerror.png

Apache Access Log

# tail -f /var/log/httpd/access_log
127.0.0.1 - - [28/Feb/2015:22:12:32 +0900] "GET /iis/ HTTP/1.1" 502 465 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; MASPJS; rv:11.0) like Gecko"

事象の改善方法

調べているといくつか設定方法はあることがわかった。以下に調べた範囲の情報を記載します。

1. proxy-initial-not-pooled

下記サイトを参考に設定しました。
http://qiita.com/mist_dev/items/e902854998074fe4bef1

# cat /etc/httpd/conf.d/proxy.conf
<Location /iis>
  SetEnv proxy-initial-not-pooled 1
</Location>

ProxyPass /iis http://172.31.12.130/
ProxyPassReverse /iis http://172.31.12.130/

# /etc/init.d/httpd graceful

2. force-proxy-request & proxy-nokeepalive

下記サイトを参考に設定しました。
http://startnews24.com/?p=23553
http://se-suganuma.blogspot.jp/2011/07/apachereverse-proxy502-proxy-error.html

# cat /etc/httpd/conf.d/proxy.conf
<Location /iis>
  SetEnv force-proxy-request-1.0 1  
  SetEnv proxy-nokeepalive 1 
</Location>

ProxyPass /iis http://172.31.12.130/
ProxyPassReverse /iis http://172.31.12.130/

# /etc/init.d/httpd graceful

3. retry & keepalive

下記サイトを参考に設定しました。
http://serverfault.com/questions/185894/proxy-error-502-reason-error-reading-from-remote-server-with-apache-2-2-3-de
http://stackoverflow.com/questions/169453/bad-gateway-502-error-with-apache-mod-proxy-and-tomcat

# cat /etc/httpd/conf.d/proxy.conf
<Location /iis>
</Location>

ProxyPass /iis http://172.31.12.130/ retry=1 acquire=3000 timeout=600 Keepalive=On
ProxyPassReverse /iis http://172.31.12.130/

# /etc/init.d/httpd graceful

結果

1と2の設定をそれぞれ試してみたが、今のところは502がでていないので改善されている模様。

※同様の内容が下記で議論されていました。
http://stackoverflow.com/questions/12303087/502-proxy-errors-between-iis-and-apache2

補足

リバースプロキシに関する設定は下記サイトを参考としました。
http://dev.classmethod.jp/server-side/server/introduction_mod_proxy/

各環境変数の意味は下記サイトを参照。
http://httpd.apache.org/docs/2.2/ja/mod/mod_proxy_http.html

37
33
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
37
33