2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ApacheのリバースProxyで、振り分け先に認証Proxy経由で転送する

Posted at

ApacheのリバースProxyで、振り分け先に認証Proxy経由で転送する

やりたいこと

イントラネット内にあるWebサーバをリバースProxyとして、リクエストをインターネット上にあるサーバに振り分けたい。
振り分け先サーバはインターネット上にあり、イントラネットからの通信はProxy(Basic認証)を経由する。

構成図

構成図.png

要約

Apacheの設定ファイルに以下のように書けばできる

ProxyRequests Off
ProxyPass [Webサーバで受け付けるパス] [振り分け先]
ProxyPassReverse [Webサーバで受け付けるパス] [振り分け先]
ProxyRemote [Proxyを通す対象] [ProxyURL]
Header add Proxy-Authorization "Basic [認証ProxyのID:PWをbase64エンコードした文字列]"

設定例

ProxyRequests Off
ProxyPass / http://xxx.xxx.xxx.xxx:3000
ProxyPassReverse / http://xxx.xxx.xxx.xxx:3000
ProxyRemote * http://192.168.20.5:8080
Header add Proxy-Authorization "Basic dXNlcm5hbWU6cGFzc3dvcmQ="

NGだった指定方法

ProxyRemote * http://username:password@192.168.20.5:8080

ProxyのURLにID/PWを書いてもいけるのではないか・・・と思ったけど、
Apache起動時に以下のエラーになった。

ProxyRemote: Bad syntax for a remote proxy server (bad port number)

どうやらusername:password:をポート番号の区切り文字と認識されて
password@192.168.20.5:8080は、ポート番号の形式としてNGと判定されたっぽい

参考

https://httpd.apache.org/docs/2.4/ja/mod/mod_proxy.html
https://httpd.apache.org/docs/2.4/ja/mod/mod_headers.html
https://qiita.com/charon/items/5406c23494eeee733dc1
https://www.server-world.info/query?os=CentOS_7&p=httpd2&f=2

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?