{"id":7012,"date":"2019-01-17T21:24:42","date_gmt":"2019-01-17T20:24:42","guid":{"rendered":"https:\/\/pi3g.com\/?p=7012"},"modified":"2019-01-17T21:27:45","modified_gmt":"2019-01-17T20:27:45","slug":"envoy-as-http-2-front-proxy-enabling-http-2-for-envoy-aka-h2","status":"publish","type":"post","link":"https:\/\/pi3g.com\/de\/envoy-as-http-2-front-proxy-enabling-http-2-for-envoy-aka-h2\/","title":{"rendered":"envoy als http 2 Frontproxy - Aktivierung von http 2 f\u00fcr envoy (auch bekannt als h2)"},"content":{"rendered":"<p>Out of the box envoy is not configured to set up connections with clients connecting to it with the new HTTP\/2.<\/p>\n<p>HTTP\/2 is optimized for the modern web, with binary headers, etc. \u2013 higher speed. <\/p>\n<p>Since envoy is capable of speaking HTTP\/2 to clients, it is a no-brainer to set it up.<\/p>\n<p>And the setup is really <strong>easy<\/strong>, too. You just add <strong>one<\/strong> line in the common_tls_context of your listener:<\/p>\n<blockquote>\n<pre>alpn_protocols: [ \"h2,http\/1.1\" ]<\/pre>\n<\/blockquote>\n<p>That\u2019s it. (The quotes should be normal quotes, in case WordPress messes these up)<\/p>\n<p>ALPN stands for <a href=\"https:\/\/en.wikipedia.org\/wiki\/Application-Layer_Protocol_Negotiation\" target=\"_blank\">Application-Layer Protocol Negotiation<\/a>&nbsp; &#8211; it is apparently needed for HTTP\/2 to work. <\/p>\n<p>By default, the http_connection_manager envoy filter will support both HTTP1 and HTTP2 in the mode AUTO. <\/p>\n<p>By adding the alpn_protocols you allow this functionality to actually be used.<\/p>\n<h2>My envoy.yaml for your reference<\/h2>\n<p>I\u2019m going to reproduce <strong>my entire envoy.yaml <\/strong>so you see the context the line has to be put in:<\/p>\n<p>static_resources:<br \/>&nbsp;&nbsp; listeners:<br \/>&nbsp;&nbsp; &#8211; address:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; socket_address:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; address: 0.0.0.0<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; port_value: 80<br \/>&nbsp;&nbsp;&nbsp;&nbsp; filter_chains:<br \/>&nbsp;&nbsp;&nbsp;&nbsp; &#8211; filters:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8211; name: envoy.http_connection_manager<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; config:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; codec_type: auto<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; stat_prefix: ingress_http<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; route_config:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; virtual_hosts:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8211; name: backend<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; domains: [&#8220;*&#8221;]<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; routes:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8211; match: { prefix: &#8220;\/&#8221; }<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; redirect:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; path_redirect: &#8220;\/&#8221;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; https_redirect: true<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; http_filters:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8211; name: envoy.router<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; config: {}<br \/>&nbsp;&nbsp; &#8211; address:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; socket_address:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; address: 0.0.0.0<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; port_value: 443<br \/>&nbsp;&nbsp;&nbsp;&nbsp; filter_chains:<br \/>&nbsp;&nbsp;&nbsp;&nbsp; &#8211; tls_context:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; common_tls_context:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tls_certificates:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8211; certificate_chain: { filename: &#8220;\/etc\/example-com.crt&#8221; }<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private_key: { filename: &#8220;\/etc\/example-com.key&#8221; }<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alpn_protocols: [ &#8220;h2,http\/1.1&#8221; ]<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; filters:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8211; name: envoy.http_connection_manager<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; config:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; stat_prefix: ingress_https<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; route_config:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; virtual_hosts:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8211; name: backend<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; domains: [&#8220;*&#8221;]<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; routes:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8211; match: { prefix: &#8220;\/&#8221; }<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; route: { cluster: target_taxgod }<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; http_filters:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8211; name: envoy.router<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; config: {}<br \/>&nbsp;&nbsp; clusters:<br \/>&nbsp;&nbsp; &#8211; name: target_taxgod<br \/>&nbsp;&nbsp;&nbsp;&nbsp; connect_timeout: 0.25s<br \/>&nbsp;&nbsp;&nbsp;&nbsp; type: strict_dns<br \/>&nbsp;&nbsp;&nbsp;&nbsp; lb_policy: round_robin<br \/>&nbsp;&nbsp;&nbsp;&nbsp; hosts:<br \/>&nbsp;&nbsp;&nbsp;&nbsp; &#8211; socket_address:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; address: taxgod<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; port_value: 3000<br \/>\nadmin:<br \/>&nbsp;&nbsp; access_log_path: &#8220;\/tmp\/envoy.log&#8221;<br \/>&nbsp;&nbsp; address:<br \/>&nbsp;&nbsp;&nbsp;&nbsp; socket_address:<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; address: 0.0.0.0<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; port_value: 9901<\/p>\n<p><\/p>\n<p>This envoy.yaml listens on port 80 and port 443. HTTP requests to port 80 are redirected to port 443. All traffic is sent to a docker container \u201ctaxgod\u201d on the same docker network. Refer to this article by me for details.<\/p>\n<p><\/p>\n<p>Please don\u2019t expect copy pasting this whole thing to work \u2013 WordPress unfortunately is too clever for it\u2019s own good sometimes, and messes up all kinds of characters and code formatting.<\/p>\n<h2>References:<\/h2>\n<ul>\n<li><a href=\"https:\/\/en.wikipedia.org\/wiki\/Application-Layer_Protocol_Negotiation\">https:\/\/en.wikipedia.org\/wiki\/Application-Layer_Protocol_Negotiation<\/a><\/li>\n<li><a href=\"https:\/\/www.envoyproxy.io\/docs\/envoy\/latest\/api-v2\/config\/filter\/network\/http_connection_manager\/v2\/http_connection_manager.proto#enum-config-filter-network-http-connection-manager-v2-httpconnectionmanager-codectype\">https:\/\/www.envoyproxy.io\/docs\/envoy\/latest\/api-v2\/config\/filter\/network\/http_connection_manager\/v2\/http_connection_manager.proto#enum-config-filter-network-http-connection-manager-v2-httpconnectionmanager-codectype<\/a><\/li>\n<li><a href=\"https:\/\/www.envoyproxy.io\/docs\/envoy\/latest\/intro\/arch_overview\/ssl.html?highlight=common\">https:\/\/www.envoyproxy.io\/docs\/envoy\/latest\/intro\/arch_overview\/ssl.html?highlight=common<\/a><\/li>\n<li><a href=\"https:\/\/www.envoyproxy.io\/docs\/envoy\/latest\/api-v2\/api\/v2\/auth\/cert.proto.html?highlight=common#auth-commontlscontext\">https:\/\/www.envoyproxy.io\/docs\/envoy\/latest\/api-v2\/api\/v2\/auth\/cert.proto.html?highlight=common#auth-commontlscontext<\/a> \u2013&gt; I got the information how to set alpn properly (where to put it in the configuration file, and what to put inside it) up from here<\/li>\n<li><a href=\"https:\/\/github.com\/envoyproxy\/envoy\/issues\/3394\">https:\/\/github.com\/envoyproxy\/envoy\/issues\/3394<\/a> \u2013&gt; this got me started in the right direction. I had never heard of ALPN before I read this.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Standardm\u00e4\u00dfig ist envoy nicht f\u00fcr den Aufbau von Verbindungen mit Clients konfiguriert, die sich mit dem neuen HTTP\/2 verbinden. HTTP\/2 ist f\u00fcr das moderne Web optimiert, mit bin\u00e4ren Headern, etc. - h\u00f6here Geschwindigkeit. Da envoy in der Lage ist, HTTP\/2 an Clients weiterzugeben, ist es ein Kinderspiel, es einzurichten. Und die Einrichtung...<\/p>","protected":false},"author":830,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[402],"tags":[485,481,482,484,483],"class_list":["post-7012","post","type-post","status-publish","format-standard","hentry","category-development","tag-enable-http-2","tag-envoy","tag-h2","tag-http-2","tag-http-1-1"],"_links":{"self":[{"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/posts\/7012","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/users\/830"}],"replies":[{"embeddable":true,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/comments?post=7012"}],"version-history":[{"count":2,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/posts\/7012\/revisions"}],"predecessor-version":[{"id":7014,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/posts\/7012\/revisions\/7014"}],"wp:attachment":[{"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/media?parent=7012"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/categories?post=7012"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/tags?post=7012"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}