Skip to content

Commit 15e768c

Browse files
authored
Merge pull request #35 from macbre/http3
HTTP/3 support
2 parents 4f4a71c + 92a2188 commit 15e768c

File tree

5 files changed

+92
-27
lines changed

5 files changed

+92
-27
lines changed

.github/workflows/dockerimage.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
push:
55
branches: [ master ]
66
pull_request:
7-
branches: [ master ]
87

98
jobs:
109

@@ -55,4 +54,12 @@ jobs:
5554
grep --fixed-strings '<p>It works!</p>' /tmp/h2
5655
5756
57+
docker run --rm --network host ymuski/curl-http3 \
58+
curl -v --insecure https://localhost:8889 --http3 2>&1 | tee /tmp/h3
59+
60+
grep --fixed-strings '< HTTP/3 200' /tmp/h3
61+
grep --fixed-strings '< server: nginx' /tmp/h3
62+
grep --fixed-strings '< alt-svc: h3-27=":8889"; ma=86400, h3-28=":8889"; ma=86400, h3-29=":8889"; ma=86400' /tmp/h3
63+
grep --fixed-strings '<p>It works!</p>' /tmp/h3
64+
5865
docker logs test_nginx

Dockerfile

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG NGINX_VERSION=1.19.10
1+
ARG NGINX_VERSION=1.19.6
22

33
# https://github.com/google/ngx_brotli
44
ARG NGX_BROTLI_COMMIT=9aec15e2aa6feea2113119ba06460af70ab3ea62
@@ -47,6 +47,9 @@ ARG CONFIG="\
4747
--with-compat \
4848
--with-file-aio \
4949
--with-http_v2_module \
50+
--with-http_v3_module \
51+
--with-openssl=/usr/src/quiche/deps/boringssl \
52+
--with-quiche=/usr/src/quiche \
5053
--add-module=/usr/src/ngx_brotli \
5154
"
5255

@@ -62,6 +65,7 @@ RUN \
6265
gcc \
6366
libc-dev \
6467
make \
68+
patch \
6569
openssl-dev \
6670
pcre-dev \
6771
zlib-dev \
@@ -80,10 +84,11 @@ RUN \
8084
cmake
8185

8286
COPY nginx.pub /tmp/nginx.pub
87+
WORKDIR /usr/src/
8388

8489
RUN \
85-
echo "Compiling nginx $NGINX_VERSION with brotli $NGX_BROTLI_COMMIT" \
86-
&& mkdir -p /usr/src/ngx_brotli \
90+
echo "Compiling nginx $NGINX_VERSION with brotli $NGX_BROTLI_COMMIT ..." \
91+
&& mkdir /usr/src/ngx_brotli \
8792
&& cd /usr/src/ngx_brotli \
8893
&& git init \
8994
&& git remote add origin https://github.com/google/ngx_brotli.git \
@@ -97,19 +102,23 @@ RUN \
97102
&& export GNUPGHOME="$(mktemp -d)" \
98103
&& gpg --import /tmp/nginx.pub \
99104
&& gpg --batch --verify nginx.tar.gz.asc nginx.tar.gz \
100-
&& mkdir -p /usr/src \
101-
&& tar -zxC /usr/src -f nginx.tar.gz
105+
&& tar -zxC /usr/src -f nginx.tar.gz \
106+
&& echo "Fetching quiche and applying the patch..." \
107+
&& cd /usr/src \
108+
&& git clone --recursive https://github.com/cloudflare/quiche \
109+
&& cd /usr/src/nginx-$NGINX_VERSION \
110+
&& patch -p01 < /usr/src/quiche/extras/nginx/nginx-1.16.patch
102111

103112
RUN \
104-
cd /usr/src/nginx-$NGINX_VERSION \
105-
&& ./configure $CONFIG --with-debug \
106-
&& make -j$(getconf _NPROCESSORS_ONLN) \
107-
&& mv objs/nginx objs/nginx-debug \
108-
&& mv objs/ngx_http_xslt_filter_module.so objs/ngx_http_xslt_filter_module-debug.so \
109-
&& mv objs/ngx_http_image_filter_module.so objs/ngx_http_image_filter_module-debug.so \
110-
&& mv objs/ngx_http_geoip_module.so objs/ngx_http_geoip_module-debug.so \
111-
&& mv objs/ngx_stream_geoip_module.so objs/ngx_stream_geoip_module-debug.so \
112-
&& ./configure $CONFIG \
113+
echo "Setting up rust ..." \
114+
&& curl https://sh.rustup.rs -sSf | sh -s -- -y -q \
115+
&& export PATH="$HOME/.cargo/bin:$PATH" \
116+
&& rustc --version \
117+
&& cargo --version \
118+
\
119+
&& echo "Building nginx ..." \
120+
&& cd /usr/src/nginx-$NGINX_VERSION \
121+
&& ./configure $CONFIG --build="quiche-$(git --git-dir=/usr/src/quiche/.git rev-parse --short HEAD)" \
113122
&& make -j$(getconf _NPROCESSORS_ONLN)
114123

115124
RUN \
@@ -120,11 +129,6 @@ RUN \
120129
&& mkdir -p /usr/share/nginx/html/ \
121130
&& install -m644 html/index.html /usr/share/nginx/html/ \
122131
&& install -m644 html/50x.html /usr/share/nginx/html/ \
123-
&& install -m755 objs/nginx-debug /usr/sbin/nginx-debug \
124-
&& install -m755 objs/ngx_http_xslt_filter_module-debug.so /usr/lib/nginx/modules/ngx_http_xslt_filter_module-debug.so \
125-
&& install -m755 objs/ngx_http_image_filter_module-debug.so /usr/lib/nginx/modules/ngx_http_image_filter_module-debug.so \
126-
&& install -m755 objs/ngx_http_geoip_module-debug.so /usr/lib/nginx/modules/ngx_http_geoip_module-debug.so \
127-
&& install -m755 objs/ngx_stream_geoip_module-debug.so /usr/lib/nginx/modules/ngx_stream_geoip_module-debug.so \
128132
&& strip /usr/sbin/nginx* \
129133
&& strip /usr/lib/nginx/modules/*.so \
130134
\
@@ -150,7 +154,7 @@ ARG NGINX_VERSION
150154
COPY --from=base /tmp/runDeps.txt /tmp/runDeps.txt
151155
COPY --from=base /etc/nginx /etc/nginx
152156
COPY --from=base /usr/lib/nginx/modules/*.so /usr/lib/nginx/modules/
153-
COPY --from=base /usr/sbin/nginx /usr/sbin/nginx-debug /usr/sbin/
157+
COPY --from=base /usr/sbin/nginx /usr/sbin/
154158
COPY --from=base /usr/share/nginx/html/* /usr/share/nginx/html/
155159
COPY --from=base /usr/bin/envsubst /usr/local/bin/envsubst
156160
COPY --from=base /etc/ssl/dhparam.pem /etc/ssl/dhparam.pem

readme.md

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
## What is this?
22

3-
Stable and up-to-date [nginx](https://nginx.org/en/CHANGES) with [Google's `brotli` compression](https://github.com/google/ngx_brotli) and [Grade A+ SSL config](https://ssl-config.mozilla.org/)
3+
Stable and up-to-date [nginx](https://nginx.org/en/CHANGES) with [QUIC + HTTP/3 support](https://developers.cloudflare.com/http3/), [Google's `brotli` compression](https://github.com/google/ngx_brotli) and [Grade A+ SSL config](https://ssl-config.mozilla.org/)
44

55

66
## How to use this image
77
As this project is based on the official [nginx image](https://hub.docker.com/_/nginx/) look for instructions there. In addition to the standard configuration directives, you'll be able to use the brotli module specific ones, see [here for official documentation](https://github.com/google/ngx_brotli#configuration-directives)
88

99
```
10-
docker pull macbre/nginx-brotli:1.19.10
10+
docker pull macbre/nginx-brotli:1.19.6-http3
1111
```
1212

13+
Please refer to [the list of image tags](https://hub.docker.com/_/nginx/) as there more recent nginx versions there (but without http3 support).
14+
1315
## What's inside
1416

1517
```
1618
$ docker run -it macbre/nginx-brotli nginx -V
17-
nginx version: nginx/1.19.10
19+
nginx version: nginx/1.19.6 (quiche-567cc5e)
1820
built by gcc 10.2.1 20201203 (Alpine 10.2.1_pre1)
19-
built with OpenSSL 1.1.1k 25 Mar 2021
21+
built with OpenSSL 1.1.1 (compatible; BoringSSL) (running with BoringSSL)
2022
TLS SNI support enabled
21-
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-threads --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-stream_realip_module --with-stream_geoip_module=dynamic --with-http_slice_module --with-mail --with-mail_ssl_module --with-compat --with-file-aio --with-http_v2_module --add-module=/usr/src/ngx_brotli
23+
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-threads --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-stream_realip_module --with-stream_geoip_module=dynamic --with-http_slice_module --with-mail --with-mail_ssl_module --with-compat --with-file-aio --with-http_v2_module --with-http_v3_module --with-openssl=/usr/src/quiche/deps/boringssl --with-quiche=/usr/src/quiche --add-module=/usr/src/ngx_brotli --build=quiche-567cc5e
2224
```
2325

2426
## SSL Grade A+ handling
@@ -33,3 +35,40 @@ Please refer to [Mozilla's SSL Configuration Generator](https://ssl-config.mozil
3335

3436
* `.conf` files mounted in `/etc/nginx/main.d` will be included in the `main` nginx context (e.g. you can call [`env` directive](http://nginx.org/en/docs/ngx_core_module.html#env) there)
3537
* `.conf` files mounted in `/etc/nginx/conf.d` will be included in the `http` nginx context
38+
39+
## QUIC + HTTP/3 support
40+
41+
<img width="577" alt="Screenshot 2021-05-19 at 16 31 10" src="https://user-images.githubusercontent.com/1929317/118840921-baf7d300-b8bf-11eb-8c0f-e57d573a28ce.png">
42+
43+
Please refer to `tests/https.conf` config file for an example config used by the tests. And to Cloudflare docs on [how to enable http/3 support in your browser](https://developers.cloudflare.com/http3/firefox).
44+
45+
```
46+
server {
47+
# quic and http/3
48+
listen 443 quic reuseport;
49+
50+
# http/2
51+
listen 443 ssl http2;
52+
53+
server_name localhost; # customize to match your domain
54+
55+
# you need to mount these files when running this container
56+
ssl_certificate /etc/nginx/ssl/localhost.crt;
57+
ssl_certificate_key /etc/nginx/ssl/localhost.key;
58+
59+
# Enable all TLS versions (TLSv1.3 is required for QUIC).
60+
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
61+
62+
# 0-RTT QUIC connection resumption
63+
ssl_early_data on;
64+
65+
# Add Alt-Svc header to negotiate HTTP/3.
66+
add_header alt-svc 'h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400';
67+
68+
location / {
69+
# your config
70+
}
71+
}
72+
```
73+
74+
Refer to `run-docker.sh` script on how to run this container and properly mount required config files and assets.

run-docker.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/bin/sh
22
docker run --rm \
33
-p 0.0.0.0:8888:80 \
4-
-p 0.0.0.0:8889:443 \
4+
-p 0.0.0.0:8889:443/tcp \
5+
-p 0.0.0.0:8889:443/udp \
56
-v "$PWD/tests":/static:ro \
67
-v "$PWD/tests/static.conf":/etc/nginx/conf.d/static.conf:ro \
78
-v "$PWD/tests/https.conf":/etc/nginx/conf.d/https.conf:ro \

tests/https.conf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
server {
2+
# quic and http/3
3+
listen 443 quic reuseport;
4+
5+
# http/2
26
listen 443 ssl http2;
7+
38
server_name localhost;
49

510
# openssl-generated pair for local development
611
# https://letsencrypt.org/docs/certificates-for-localhost/
712
ssl_certificate /etc/nginx/ssl/localhost.crt;
813
ssl_certificate_key /etc/nginx/ssl/localhost.key;
914

15+
# Enable all TLS versions (TLSv1.3 is required for QUIC).
16+
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
17+
18+
# 0-RTT QUIC connection resumption
19+
ssl_early_data on;
20+
21+
# Add Alt-Svc header to negotiate HTTP/3.
22+
add_header alt-svc 'h3-27=":8889"; ma=86400, h3-28=":8889"; ma=86400, h3-29=":8889"; ma=86400';
23+
1024
location / {
1125
root /static;
1226

0 commit comments

Comments
 (0)