-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
[Protocol] NGINX doesn't support HTTP/1.1 on h2c ports #226
Comments
@zhangzhhz Can I see your trojan server config? (redact as needed) |
Actually, I would suggest not use http/2 but listen for http/1.1 in your nginx (and change the alpn option in trojan server config accordingly). |
@GreaterFire, thanks, it does work now after removing http2 and h2 from Nginx and trojan. I thought http2 was supported in majority of cases now (that's why I added it in trojan configuration in the first place). Can trojan have better support for http2? |
I'll try to look into this. |
It's NGINX's issue actually (https://trac.nginx.org/nginx/ticket/816). It supports both 1.1 and 2 simultaneously on its 443 port, but it doesn't support plain 1.1 and 2 simultaneously on its 80 port. |
This is a valuable problem. It points out a distinction between NGINX behind trojan and the standalone NGINX itself when HTTP/2 is present. As HTTP/2 gets more prevalent, we cannot ignore this issue, because this distinction can be used to precisely identify the existence of trojan in front of NGINX. I'll repeat the problem of NGINX here. If we have a standalone NGINX listen on 443 with both http2 and ssl, this port actually supports HTTP/1.1, because NGINX will adjust to the lower version based on the ALPN negotiation result. However, if we let NGINX listen on 80 with only http2 and let trojan do the SSL termination, NGINX has no idea what the version of HTTP is (because the ALPN negotiation is done in trojan) and will assume HTTP/2 no matter what. If the protocol is, in fact, HTTP/1.1, NGINX will simply ignore that and respond with an HTTP/2 message. |
After a closer look at the NGINX bug tracker (https://trac.nginx.org/nginx/ticket/816), it seems that NGINX is against the standard. An HTTP/2 port should be backwards compatible with HTTP/1.1. |
The problem lies here (https://github.com/nginx/nginx/blob/9e07862d6e9d37041a42bbfa34dd1f56ed547505/src/http/ngx_http_request.c#L324-L331) where NGINX will choose to use HTTP/2 unilaterally if the config says so. Too hard to patch this. |
easy to solve this problem. |
@cybmp3 This doesn't solve the problem when you have to serve HTTP/1.1 over the h2c port because the client browser doesn't support h2. |
Yes.If you browser http://example.com you will get a normal website(http1.1). |
I mentioned it in #171, but I wonder if it is reasonable to mitigate this by redirecting to different |
@WillyPillow This will break the current config format and will be more confusing to configure. I recommend we put it on hold for now. |
Technically one should be able to preserve backwards compatibility by, say, adding a new config entry that maps ALPNs to port numbers, and using the port specified in |
@WillyPillow Good idea. I'll try to design this scheme. |
…entry `ssl.alpn_port_override` that changes the remote port according to the received ALPN.
that changes the remote port according to the ALPN. Fixes trojan-gfw#171 and trojan-gfw#226.
that changes the remote port according to the ALPN. Fixes trojan-gfw#171 and trojan-gfw#226.
that changes the remote port according to the ALPN. Fixes trojan-gfw#171 and trojan-gfw#226.
* Add an optional config entry `ssl.alpn_port_override` that changes the remote port according to the ALPN. Fixes #171 and #226. * Handle `ssl.alpn_port_override` only when the request is not valid. * Fixes to `ssl.alpn_port_override` Co-authored-by: GreaterFire <32649575+GreaterFire@users.noreply.github.com>
Hi,
I have trojan running at 443, redirecting to 80 which Nginx runs at. Nginx reverse proxies notebook.DOMAIN.TLD to http://localhost:6600 which runs a jupyter notebook.
I can connect to notebook.DOMAIN.TLD and see a list of notebooks and other files, but opening a notebook will give "Connection failed" error:
Firefox console shows:
There is no problem if I stop trojan and run Nginx at 443 directly.
Can someone give me some pointers?
Thanks.
My Nginx server config for notebook.DOMAIN.TLD is as follows:
The text was updated successfully, but these errors were encountered: