Tinyproxy를 사용하여 정방향 프록시에서 역방향 프록시로의 통신 설정

Tinyproxy를 사용하여 정방향 프록시에서 역방향 프록시로의 통신 설정

Tinyproxy(버전 1.8.3)에서 지원하는 정방향 프록시와 역방향 프록시를 연결하는 데 문제가 있습니다. 구성에 문제가 있는건지 모르겠네요.

저는 Debian GNU/Linux 8.9(jessie)를 실행하는 4개의 가상 머신으로 이 프록시를 테스트하고 있습니다. 이러한 머신은 클라이언트, 정방향 프록시, 역방향 프록시 및 서버를 나타냅니다. 정방향 프록시와 역방향 프록시 간의 통신을 설정하고 있습니다.

서버는 "작동합니다"라는 기본 HTML 페이지를 반환하는 Apache 서버를 실행하고 있습니다.

원하는 동작은 클라이언트가 서버와 상호 작용하는 역방향 프록시로 업스트림하는 순방향 프록시를 통해 서버와 통신하는 것입니다. 클라이언트(10.0.2.33) -> 정방향 프록시(10.0.2.35) -> 역방향 프록시(10.0. 2.36) -> 서버 (10.0.2.34)

시스템을 테스트하기 위해 클라이언트 시스템에서 다음 컬 명령을 사용합니다.

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)는 "를 요청하면 서버(10.0.2.34)를 요청합니다.http://10.0.2.36:8888/

다음을 사용하여 역방향 프록시에 대해 컬을 실행해야 합니다.

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

관련 정보