Skip to content

Commit 11b838a

Browse files
authored
Implement HTTPv3 and QUIC NGINX directives (#353)
1 parent ed41cc7 commit 11b838a

File tree

10 files changed

+109
-0
lines changed

10 files changed

+109
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
\#*
77
!molecule.crt
88
!molecule.key
9+
!rand.key
910

1011
# OS Specific #
1112
###############

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## 0.7.1 (Unreleased)
44

5+
ENHANCEMENTS:
6+
7+
- Directives documented for `http_v3` module are implemented.
8+
59
BUG FIXES:
610

711
- Add handler to reload NGINX when SSL cert or key is changed.

defaults/main/template.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ nginx_config_main_template:
7272
- /etc/nginx/conf.d/*.conf
7373
# stream:
7474
# include: /etc/nginx/conf.d/stream/*.conf # String or a list of strings
75+
# quic:
76+
# bpf: false # Boolean
7577

7678
# Enable creating dynamic templated NGINX HTTP configuration files.
7779
# Defaults will not produce a valid configuration. Instead they are meant to showcase
@@ -204,6 +206,7 @@ nginx_config_http_template:
204206
port: 80
205207
default_server: true # Boolean
206208
ssl: false # Boolean
209+
quic: false # Boolean
207210
proxy_protocol: false # Boolean
208211
fastopen: 12 # Number
209212
backlog: 511 # Number
@@ -278,6 +281,16 @@ nginx_config_http_template:
278281
max_concurrent_streams: 128 # Number -- Not available in the 'location' context
279282
recv_buffer_size: 256k # Only available in the 'http' context
280283
recv_timeout: 20s # Not available in the 'location' context
284+
http3:
285+
enable: false # Boolean
286+
hq: false # Boolean
287+
max_concurrent_streams: 128 # Number
288+
stream_buffer_size: 64k
289+
quic:
290+
active_connection_id_limit: 2
291+
gso: false # Boolean
292+
host_key: /path/to/file
293+
retry: false # Boolean
281294
ssl: # Configure SSL
282295
buffer_size: 16k
283296
certificate: /path/to/file # String or a list of strings

molecule/common/files/ssl/rand.key

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
E�4�h���4�֚Y�� &i"/m�{�7��<%�J%f���^��`R�P��[ �,6=!�>Z� �o�K�cG�

molecule/default/converge.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
- src: ../common/files/ssl/molecule.key
2727
dest: /etc/ssl/private
2828
backup: true
29+
- src: ../common/files/ssl/rand.key
30+
dest: /etc/ssl/private
31+
backup: true
2932

3033
nginx_config_main_template_enable: true
3134
nginx_config_main_template:
@@ -67,6 +70,8 @@
6770
threads: 32
6871
timer_resolution: 1s
6972
working_directory: /etc/nginx
73+
quic:
74+
bpf: false
7075
events:
7176
accept_mutex: false
7277
accept_mutex_delay: 500ms
@@ -236,6 +241,11 @@
236241
max_concurrent_streams: 31
237242
recv_buffer_size: 128k
238243
recv_timeout: 10s
244+
http3:
245+
enable: true
246+
hq: false
247+
max_concurrent_streams: 100
248+
stream_buffer_size: 32k
239249
ssl:
240250
buffer_size: 16k
241251
certificate: /etc/ssl/certs/molecule.crt
@@ -257,6 +267,7 @@
257267
- TLSv1
258268
- TLSv1.1
259269
- TLSv1.2
270+
- TLSv1.3
260271
reject_handshake: false
261272
session_cache:
262273
builtin:
@@ -569,6 +580,8 @@
569580
port: 443
570581
default_server: true
571582
ssl: false
583+
quic: true
584+
reuseport: true
572585
so_keepalive:
573586
keepidle: 30m
574587
keepintvl: 5
@@ -585,6 +598,14 @@
585598
http2:
586599
enable: false
587600
chunk_size: 8k
601+
http3:
602+
enabled: false
603+
hq: true
604+
quic:
605+
active_connection_id_limit: 10
606+
gso: false
607+
retry: false
608+
host_key: /etc/ssl/private/rand.key
588609
auth_basic:
589610
realm: false
590611
log:

molecule/push/converge.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@
3030
- src: ../common/files/ssl/molecule.key
3131
dest: /etc/ssl/private
3232
backup: true
33+
- src: ../common/files/ssl/rand.key
34+
dest: /etc/ssl/private
35+
backup: true

templates/core.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ timer_resolution {{ main['timer_resolution'] }};
8383
{% if main['working_directory'] is defined %}
8484
working_directory {{ main['working_directory'] }};
8585
{% endif %}
86+
{% if main['quic'] is defined %}
87+
{% from 'http/modules.j2' import quic with context %}
88+
{{ quic(main['quic'], 'global') }}
89+
{% endif %}
8690
{% endmacro %}
8791

8892
{% macro events(events) %}

templates/http/core.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ lingering_timeout {{ core['lingering_timeout'] }};
141141
listen {{ listen['address'] if listen['address'] is defined }}{{ ':' if listen['address'] is defined and listen['port'] is defined }}{{ listen['port'] if listen['port'] is defined -}}
142142
{{- ' default_server' if listen['default_server'] is defined and listen['default_server'] is boolean and listen['default_server'] | bool -}}
143143
{{- ' ssl' if listen['ssl'] is defined and listen['ssl'] is boolean and listen['ssl'] | bool -}}
144+
{{- ' quic' if listen['quic'] is defined and listen['quic'] is boolean and listen['quic'] | bool -}}
144145
{{- ' proxy_protocol' if listen['proxy_protocol'] is defined and listen['proxy_protocol'] is boolean and listen['proxy_protocol'] | bool -}}
145146
{{- (' setfib=' + listen['setfib'] | string) if listen['setfib'] is defined -}}
146147
{{- (' fastopen=' + listen['fastopen'] | string) if listen['fastopen'] is defined and listen['fastopen'] is number -}}

templates/http/default.conf.j2

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
{% from 'http/modules.j2' import http2 with context %}
1313
{{ http2(item['config']['http2'], 'http') }}
1414
{%- endif %}
15+
{% if item['config']['http3'] is defined %}
16+
{% from 'http/modules.j2' import http3 with context %}
17+
{{ http3(item['config']['http3']) }}
18+
{%- endif %}
19+
{% if item['config']['quic'] is defined %}
20+
{% from 'http/modules.j2' import quic with context %}
21+
{{ quic(item['config']['quic']) }}
22+
{%- endif %}
1523
{% if item['config']['ssl'] is defined %}
1624
{% from 'http/ssl.j2' import ssl with context %}
1725
{{ ssl(item['config']['ssl']) }}
@@ -134,6 +142,19 @@ server {
134142
{{ http2(server['http2'], 'server') }}
135143
{%- endfilter %}
136144
{% endif %}
145+
{% if server['http3'] is defined %}
146+
{% from 'http/modules.j2' import http3 with context %}
147+
{% filter indent(4) %}
148+
{{ http3(server['http3']) }}
149+
{%- endfilter %}
150+
{% endif %}
151+
{% if server['quic'] is defined %}
152+
{% from 'http/modules.j2' import quic with context %}
153+
{% filter indent(4) %}
154+
{{ quic(server['quic']) }}
155+
{%- endfilter %}
156+
{% endif %}
157+
137158
{% if server['ssl'] is defined %}
138159
{% from 'http/ssl.j2' import ssl with context %}
139160
{% filter indent(4) %}

templates/http/modules.j2

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,3 +352,43 @@ http2_chunk_size {{ http2['chunk_size'] }};
352352
{% endif %}
353353

354354
{% endmacro %}
355+
356+
{# NGINX HTTP v3 -- ngx_http_v3_module #}
357+
{% macro http3(http3) %}
358+
{% if http3['enabled'] is defined and http3['enabled'] is boolean %}
359+
http3 {{ http3['enabled'] | ternary('on', 'off') }};
360+
{% endif %}
361+
{% if http3['hq'] is defined and http3['hq'] is boolean %}
362+
http3_hq {{ http3['hq'] | ternary('on', 'off') }};
363+
{% endif %}
364+
{% if http3['max_concurrent_streams'] is defined and http3['max_concurrent_streams'] is number %}
365+
http3_max_concurrent_streams {{ http3['max_concurrent_streams'] }};
366+
{% endif %}
367+
{% if http3['stream_buffer_size'] is defined %}
368+
http3_stream_buffer_size {{ http3['stream_buffer_size'] }};
369+
{% endif %}
370+
371+
{% endmacro %}
372+
373+
{# NGINX QUIC -- ngx_event_quic #} {# exposed for use and documented through ngx_http_v3_module #}
374+
{% macro quic(quic, scope='http') %}
375+
{% if scope == 'global' %}
376+
{% if quic is defined and quic['bpf'] is defined and quic['bpf'] is boolean %}
377+
quic_bpf {{ quic['bpf'] | ternary('on', 'off') }};
378+
{% endif %}
379+
{% else %}
380+
{% if quic['active_connection_id_limit'] is defined and quic['active_connection_id_limit'] is number %}
381+
quic_active_connection_id_limit {{ quic['active_connection_id_limit'] }};
382+
{% endif %}
383+
{% if quic['gso'] is defined and quic['gso'] is boolean %}
384+
quic_gso {{ quic['gso'] | ternary('on','off') }};
385+
{% endif %}
386+
{% if quic['host_key'] is defined %}
387+
quic_host_key {{ quic['host_key'] }};
388+
{% endif %}
389+
{% if quic['retry'] is defined and quic['retry'] is boolean %}
390+
quic_retry {{ quic['retry'] | ternary('on','off') }};
391+
{% endif %}
392+
{% endif %}
393+
394+
{% endmacro %}

0 commit comments

Comments
 (0)