h2conn icon indicating copy to clipboard operation
h2conn copied to clipboard

Can it support reverse proxy such as nginx?

Open jm33-m0 opened this issue 4 years ago • 10 comments

When I put the server behind nginx, and try to connect with h2.Connect(), it throws an error:

stream error: stream ID 3; PROTOCOL_ERROR

jm33-m0 avatar Jul 14 '20 07:07 jm33-m0

In the mean time, doing a normal GET over HTTP2 client works fine

jm33-m0 avatar Jul 14 '20 07:07 jm33-m0

Does it work for you if you directly connect to the server, and not through nginx? Can you give more information? I can't tell too much from the two lines in the bug description.

posener avatar Jul 14 '20 07:07 posener

It works well without nginx, it's an issue with nginx support I think Also, it's the same error if put behind Cloudflare CDN

jm33-m0 avatar Jul 14 '20 07:07 jm33-m0

My code:

	// use h2conn for duplex tunnel
	ctx, cancel = context.WithCancel(context.Background())

	h2 := h2conn.Client{Client: HTTPClient}

	conn, resp, err = h2.Connect(ctx, url)
	if err != nil {
		log.Printf("Initiate conn: %s", err)
		return
	}

jm33-m0 avatar Jul 14 '20 07:07 jm33-m0

Additional info: nginx returns code 408:

A 408 Request Timeout response code indicates that the server did not receive a complete request from the client within a specific period of time tracked by the server (i.e. the timeout period).

jm33-m0 avatar Jul 14 '20 08:07 jm33-m0

Did you configure nginx to support http2?

posener avatar Jul 14 '20 09:07 posener

Yes, http2 is enabled, and normal requests via HTTP2 work fine

jm33-m0 avatar Jul 14 '20 09:07 jm33-m0

Sorry, it will be very hard for me to debug this. Please look at nginx logs, or use tcpdump/wireshark to debug the connection. If you find anything there it will be very interesting, and see if we can work on a fix to the library.

posener avatar Jul 16 '20 06:07 posener

@jm33-m0 Have you found out the solution? If not, can you post your nginx configuration and output of curl -I -L https://your_domain?

andrew-mestas avatar Sep 17 '20 02:09 andrew-mestas

I encapsulated the HTTP2 connection in a proxy, didn't try to solve the nginx (or any kind of reverse proxy) support.

jm33-m0 avatar Sep 18 '20 05:09 jm33-m0