mitmproxy / docker-releases

🗃️ This repository has been integrated into mitmproxy/mitmproxy.
52 stars 26 forks source link

setup question: mitmproxy between hosts file and another proxy #16

Closed artemkloko closed 7 years ago

artemkloko commented 7 years ago

Hello, I am trying to implement the following setup, but I am not sure if this is possible with docker. And if it possible in what mode should I start the mitmproxy?

So in my host machine I add the following line to hosts file

127.0.0.1 static.local

I start mitmproxy dockerized with -p 80:8080 -R http://127.0.0.1:1080 I start an nginx proxy dockerized with -p 1080:80 that forwards the requests depending on their host name

If you try to open http://static.local:1080/ the request goes directly to the nginx proxy and is forwarded further on correctly.

But if you try to open http://static.local/, the request sent from mitmproxy arrives to nginx proxy as http://127.0.0.1:1080/ which the nginx proxy can not forward correctly due to missing host name.

If I run mitmproxy in transparent mode (even with cap_add: - NET_ADMIN) it is getting into an infinite loop. If I run mitmproxy in regular mode or in upstream mode (-U http://127.0.0.1:1080) and I get

HttpException('Invalid HTTP request form (expected: authority or absolute, got: relative)',)

Also all of the above setups, with the use of FoxyProxy plugin instead of hosts file - work.

I can also provide a docker-compose.yml

mhils commented 7 years ago

But if you try to open http://static.local/, the request sent from mitmproxy arrives to nginx proxy as http://127.0.0.1:1080/ which the nginx proxy can not forward correctly due to missing host name.

We auto-update the host header based on the destination passed in -R: http://docs.mitmproxy.org/en/stable/features/reverseproxy.html#host-header. You have to enable the keep_host_header option, which we added recently. I think it made it into 2., but we haven't documented it yet. If you find that it works for you, I'd appreciate a PR that adds a short sentence to the part of the docs I linked to. :)