
tinyproxy (バージョン 1.8.3) でサポートされているフォワード プロキシとリバース プロキシを接続するときに問題が発生します。設定の問題かどうかはわかりません。
私は Debian GNU/Linux 8.9 (jessie) を実行する 4 台の仮想マシンでこれらのプロキシをテストしています。これらのマシンは、クライアント、フォワード プロキシ、リバース プロキシ、およびサーバーを表します。フォワード プロキシとリバース プロキシ間の通信を設定しています。
サーバーは Apache サーバーを実行しており、「動作しています」というデフォルトの HTML ページを返します。
望ましい動作は、クライアントが、サーバーと対話するリバース プロキシの上流にあるフォワード プロキシを介してサーバーと通信することです。クライアント (10.0.2.33) -> フォワード プロキシ (10.0.2.35) -> リバース プロキシ (10.0.2.36) -> サーバー (10.0.2.34)
システムをテストするには、クライアント マシンで次の curl コマンドを使用します。
curl -v --proxy http://10.0.2.35:8888 http://10.0.2.34:80/
フォワードプロキシ構成ファイル:
## tinyproxy.conf -- tinyproxy daemon configuration file
User nobody
Group nogroup
Port 8888
Listen 10.0.2.35
BindSame yes
Timeout 600
DefaultErrorFile "/usr/share/tinyproxy/default.html"
StatFile "/usr/share/tinyproxy/stats.html"
Logfile "/var/log/tinyproxy/tinyproxy.log"
#Syslog On
LogLevel Info
PidFile "/var/run/tinyproxy/tinyproxy.pid"
#Upstream 10.0.2.36:8888 "10.0.2.0/24"
Upstream 10.0.2.36:8888
MaxClients 100
MinSpareServers 2
MaxSpareServers 5
StartServers 2
MaxRequestsPerChild 0
Allow 127.0.0.1
Allow 10.0.2.0/24
ViaProxyName "tinyproxy1"
ConnectPort 8888
ConnectPort 80
# The following two ports are used by SSL.
ConnectPort 443
ConnectPort 563
リバースプロキシ構成ファイル:
## tinyproxy.conf -- tinyproxy daemon configuration file
User nobody
Group nogroup
Port 8888
Listen 10.0.2.36
BindSame yes
Timeout 600
StatFile "/usr/share/tinyproxy/stats.html"
Logfile "/var/log/tinyproxy/tinyproxy.log"
#Syslog On
LogLevel Info
PidFile "/var/run/tinyproxy/tinyproxy.pid"
no upstream "10.0.2.34:80"
#no upstream "."
MaxClients 5
MinSpareServers 2
MaxSpareServers 5
StartServers 2
MaxRequestsPerChild 0
Allow 127.0.0.1
Allow 10.0.2.0/24
Allow 10.0.2.35
ViaProxyName "tinyproxy2"
ConnectPort 8888
ConnectPort 80
# The following two ports are used by SSL.
ConnectPort 443
ConnectPort 563
ReversePath "/" "http://10.0.2.34:80/"
ReversePath "/wired/" "http://www.wired.com/"
ReverseOnly Yes
ReverseMagic Yes
ReverseBaseURL "http://10.0.2.34:80/"
これらは Wireshark によってキャプチャされた TCP フロー ストリームです。
フロー [クライアント <-> フォワードプロキシ]
GET http://10.0.2.34:80/ HTTP/1.1
User-Agent: curl/7.38.0
Host: 10.0.2.34
Accept: */*
Proxy-Connection: Keep-Alive
HTTP/1.0 400 Bad Request
Via: 1.1 tinyproxy1 (tinyproxy/1.8.3)
Server: tinyproxy/1.8.3
Content-Type: text/html
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head><title>400 Bad Request</title></head>
<body>
<h1>Bad Request</h1>
<p>Request has an invalid URL</p>
<hr />
<p><em>Generated by tinyproxy version 1.8.3.</em></p>
</body>
</html>
フロー [フォワードプロキシ <-> リバースプロキシ]
GET http://10.0.2.34:80/ HTTP/1.0
Host: 10.0.2.34
Connection: close
Via: 1.1 tinyproxy1 (tinyproxy/1.8.3)
User-Agent: curl/7.38.0
Accept: */*
HTTP/1.0 400 Bad Request
Server: tinyproxy/1.8.3
Content-Type: text/html
Connection: close
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head><title>400 Bad Request</title></head>
<body>
<h1>Bad Request</h1>
<p>Request has an invalid URL</p>
<hr />
<p><em>Generated by tinyproxy version 1.8.3.</em></p>
</body>
</html>
これらは tinyproxy ログ ファイルの出力です。
フォワードプロキシ
CONNECT Dec 10 22:05:08 [2788]: Connect (file descriptor 6): 10.0.2.33 [10.0.2.33] at [10.0.2.35]
CONNECT Dec 10 22:05:08 [2788]: Request (file descriptor 6): GET http://10.0.2.34:80/ HTTP/1.1
INFO Dec 10 22:05:08 [2788]: Found upstream proxy 10.0.2.36:8888 for 10.0.2.34
CONNECT Dec 10 22:05:08 [2788]: Established connection to upstream proxy "10.0.2.36" using file descriptor 7.
INFO Dec 10 22:05:08 [2788]: Closed connection between local client (fd:6) and remote client (fd:7)
リバースプロキシ
CONNECT Dec 10 22:05:08 [4487]: Connect (file descriptor 6): 10.0.2.35 [10.0.2.35] at [10.0.2.36]
CONNECT Dec 10 22:05:08 [4487]: Request (file descriptor 6): GET http://10.0.2.34:80/ HTTP/1.0
ERROR Dec 10 22:05:08 [4487]: Bad request
INFO Dec 10 22:05:08 [4487]: no entity
現在、リバースプロキシマシン内のサーバーページには「curl」でアクセスできます。http://10.0.2.34:80/そしてhttp://10.0.2.36:8888/これはリバース プロキシ構成 (ReversePath) のためです。次の画像は、リバース プロキシ マシンでの Wireshark キャプチャを示しています。
このすべての構成では、クライアントのマシンで受信するのは、リバース プロキシからの 400 不正な要求エラー メッセージだけです。
答え1
この問題は解決されました。これをテストする方法は、ページをサーバーに直接要求するのではなく、リバース プロキシ マシンに要求することです。さらに、フォワード プロキシはトラフィックをリバース プロキシにアップストリームしてはなりません。
フォワード プロキシがトラフィックをアップストリームする場合、リバース プロキシはホスト/サーバーに送信された要求を理解できません。これは、フォワード プロキシとリバース プロキシの動作が異なるためです。
フォワード プロキシの正しい構成では、次の行を除外する必要があります。
upstream 10.0.2.36:8888
リバースプロキシには次のルールがあるためです。
ReversePath “/” “http://10.0.2.34:80/”
サーバーリソース(Apacheからの「It works」ページ)を要求すると、リバースプロキシ(10.0.2.36)は「http://10.0.2.36:8888/”
次のようにリバース プロキシに対して curl を実行する必要があります。
curl -v --proxy http://10.0.2.35:8888 http://10.0.2.36:8888/
すると、次の出力で構成が機能していることが分かります。
root@debian:/home/debian# curl -v --proxy http://10.0.2.35:8888 http://10.0.2.36:8888
* Rebuilt URL to: http://10.0.2.36:8888/
* Hostname was NOT found in DNS cache
* Trying 10.0.2.35...
* Connected to 10.0.2.35 (10.0.2.35) port 8888 (#0)
> GET http://10.0.2.36:8888/ HTTP/1.1
> User-Agent: curl/7.38.0
> Host: 10.0.2.36:8888
> Accept: */*
> Proxy-Connection: Keep-Alive
>
< HTTP/1.1 200 OK
< Via: 1.0 tinyproxy2 (tinyproxy/1.8.3), 1.1 tinyproxy1 (tinyproxy/1.8.3)
< Last-Modified: Mon, 11 Jun 2007 18:53:14 GMT
< Date: Tue, 12 Dec 2017 23:01:37 GMT
< Content-Type: text/html
< ETag: "2d-432a5e4a73a80"
< Set-Cookie: yummy_magical_cookie=/; path=/
* Server Apache/2.4.29 (Unix) is not blacklisted
< Server: Apache/2.4.29 (Unix)
< Content-Length: 45
< Accept-Ranges: bytes
<
<html><body><h1>It works!</h1></body></html>
* Connection #0 to host 10.0.2.35 left intact