Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
199 views
in Technique[技术] by (71.8m points)

apache - Apache2 Local Transparent Proxy

I have a local server running a 3rd party application which fetches website content (an http fetch-application for descriptive purpose).

In order to modify outgoing request headers and apply some custom ACL in the future, I want to create an apache2 transparent proxy on my local machine which will act as a proxy.

I can then use iptables to route all http requests to this local proxy which should then fetch websites on behalf of the fetch-application (without issuing redirects to the application).

The iptable rule below redirects http port 80 requests to the apache2 transparent proxy:

sudo iptables -t nat -A OUTPUT -p tcp --dport 80 -j DNAT --to-destination 127.0.0.1:3128

But now how do I configure the local proxy to transparently fetch urls?

Tried this but it ends up in a redirect looping:

<VirtualHost 127.0.0.1:3128>
    <Proxy *>
            Order deny,allow
            Allow from all
    </Proxy>
    RewriteEngine on
    RewriteRule ^/(.*) http://%{HTTP_HOST}/$1 [NC,R=302,L]
    RewriteRule ^(.*)$ http://%{HTTP_HOST}$1 [NC,P]
    ProxyPass            /  http://$1
    ProxyPassReverse     /  http://$1
</VirtualHost>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Solved.

Changed my rewrites to:

    RewriteEngine On
    RewriteRule ^(.*)$ http://%{HTTP_HOST}$1 [NC,P]
    ProxyPass            /  http://$1
    ProxyPassReverse     /  http://$1
    ProxyPreserveHost On

And my iptables command to:

sudo iptables -t nat -A OUTPUT -p tcp --dport 80  -m owner --uid-owner proxy -j DNAT --to-destination <ip>:3128

where proxy is the userid of the fetch-application.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...