Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

got 502 error when accessing http sites #36

Closed
escapezn opened this issue Jul 1, 2018 · 4 comments
Closed

got 502 error when accessing http sites #36

escapezn opened this issue Jul 1, 2018 · 4 comments

Comments

@escapezn
Copy link

escapezn commented Jul 1, 2018

1. What version of Caddy are you using (caddy -version)?

Caddy 0.11.0 (non-commercial use only)

2. What are you trying to do?

Use forwardproxy plugin to serve as a forward proxy.

3. What is your entire Caddyfile?

*.* {
 timeouts none
 tls *@*
 header / Strict-Transport-Security "max-age=31536000;"
# ...
 gzip
# ...
 proxy /ws 127.0.0.1:9613 {
  websocket
  header_upstream -Origin
 }
 forwardproxy {
  basicauth user passwd
  hide_ip
  hide_via
#  probe_resistance secretlink.localhost
  response_timeout 10
  dial_timeout     10
 }
}

4. How did you run Caddy (give the full command and describe the execution environment)?

./caddy --conf=/usr/local/caddy/Caddyfile -agree
centos 6.9 x64

5. Please paste any relevant HTTP request(s) here.

6. What did you expect to see?

7. What did you see instead (give full error messages and/or log)?

When I access https sites over the https proxy, it works fine. But for http site it shows 502 Bad Gateway in broswer.
Caddy's log here
01/Jul/2018:08:40:45 -0400 [ERROR 502 /favicon.ico] dial failed: Lookup of fai led: lookup : no such host 01/Jul/2018:08:40:46 -0400 [ERROR 502 /] dial failed: Lookup of failed: lookup : no such host 01/Jul/2018:08:40:51 -0400 [ERROR 502 /] dial failed: Lookup of failed: lookup : no such host 01/Jul/2018:08:40:53 -0400 [ERROR 502 /image] dial failed: Lookup of failed: l ookup : no such host 01/Jul/2018:08:40:54 -0400 [ERROR 502 /image] dial failed: Lookup of failed: l ookup : no such host 01/Jul/2018:08:40:54 -0400 [ERROR 502 /image] dial failed: Lookup of failed: l ookup : no such host 01/Jul/2018:08:40:54 -0400 [ERROR 502 /image] dial failed: Lookup of failed: l ookup : no such host 01/Jul/2018:08:40:54 -0400 [ERROR 502 /image] dial failed: Lookup of failed: l ookup : no such host 01/Jul/2018:08:40:54 -0400 [ERROR 502 /image] dial failed: Lookup of failed: l ookup : no such host 01/Jul/2018:08:40:54 -0400 [ERROR 502 /image] dial failed: Lookup of failed: l ookup : no such host
What surprised me most is that I have tested an exactly same caddyfile(except domain) on another server , also with caddy 0.11.0, and nothing like this happend.

8. How can someone who is starting from scratch reproduce the bug as minimally as possible?

@sergeyfrolov
Copy link
Member

sergeyfrolov commented Jul 2, 2018

Does that happen for all HTTP hosts or for particular few?
Evidently, it fails to DNS resolve the host you're trying to access. You seem to have redacted the host away, so I can't tell why this would happen.
You can try to run host your-http-host.com or dig your-http-host.com on the server with forwardproxy, and see if it's resolvable and if the resolved address is correct. Perhaps, it gets DNS poisoned?

@escapezn
Copy link
Author

escapezn commented Jul 3, 2018

Yes, as long as http sites it reports 502.
My host website on this server is absolutely accessible.
With your direction, I typed ./caddy -host my.host
It returned

Activating privacy features... done.
https://my.host
http://my.host

Looks good, right? Then I visit a http site, for example http://earthquake.usgs.gov/ over forwardproxy, the log are

02/Jul/2018:21:17:20 -0400 [ERROR 502 /] dial failed: Lookup of failed: lookup : no such host
02/Jul/2018:21:17:20 -0400 [ERROR 502 /favicon.ico] dial failed: Lookup of failed: lookup : no such host

@escapezn
Copy link
Author

escapezn commented Jul 3, 2018

It seems like forwardproxy regards the http site I visit is under my domain, http://a.com/b.html as my.host/b.html

sergeyfrolov added a commit that referenced this issue Jul 3, 2018
We stopped parsing hostname from Host field, this fixes it back.
Implicit port 80 is good not only for GET, so I changed the logic to try
port 80 on all non-connects.
While testing, I also realized that switchy omega doesn't actually presend credentials,
(somehow I thought it did), so I removed a link to it from the README.md to avoid
confusion.
Fixes #36
sergeyfrolov added a commit that referenced this issue Jul 3, 2018
We stopped parsing hostname from Host field, this fixes it back.
Implicit port 80 is good not only for GET, so I changed the logic to try
port 80 on all non-connects.
While testing, I also realized that switchy omega doesn't actually presend credentials,
(somehow I thought it did), so I removed a link to it from the README.md to avoid
confusion.
Fixes #36
@sergeyfrolov
Copy link
Member

Bug is fixed (updated version is available on caddyserver.com)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants