Skip to content

Commit

Permalink
add http3 support to nginx image, enable it for static files
Browse files Browse the repository at this point in the history
  • Loading branch information
paskal committed Dec 30, 2023
1 parent 969766c commit 30febe5
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 23 deletions.
10 changes: 8 additions & 2 deletions config/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
FROM alpine:edge
FROM macbre/nginx-http3

LABEL org.opencontainers.image.authors="Dmitry Verkhoturov <paskal.07@gmail.com>" \
org.opencontainers.image.description="nginx with brotli installed and running as non-root user, with reload for cert renewal once in six hours" \
org.opencontainers.image.documentation="https://github.com/paskal/bitrix.infra" \
org.opencontainers.image.source="https://github.com/paskal/bitrix.infra.git" \
org.opencontainers.image.title="nginx"

USER root

# for shadow package
RUN echo http://dl-2.alpinelinux.org/alpine/edge/community/ >> /etc/apk/repositories

# shadow for usermod
RUN apk add --no-cache nginx-mod-http-brotli shadow
RUN apk add --no-cache shadow

RUN usermod -u 1000 nginx
RUN groupmod -g 1000 nginx

# prepare to switching to non-root - update file permissions of directory containing
# nginx.lock and nginx.pid file
RUN chown -R --verbose nginx:nginx /var/run/nginx/ /var/cache/nginx/

# run nginx with configuration reload once in every 6 hours
CMD /bin/sh -c 'while :; do /bin/sleep 6h & wait ${!}; /usr/sbin/nginx -s reload; done & /usr/sbin/nginx -g "daemon off;"'
8 changes: 7 additions & 1 deletion config/nginx/conf.d/adminer.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
server {
listen 443 http2 ssl;
listen 443 ssl;
listen 443 quic;
add_header alt-svc 'h3=":443"; ma=86400';
ssl_certificate /etc/nginx/letsencrypt/live/favor-group.ru/fullchain.pem;
ssl_certificate_key /etc/nginx/letsencrypt/live/favor-group.ru/privkey.pem;
ssl_trusted_certificate /etc/nginx/letsencrypt/live/favor-group.ru/chain.pem;

server_name adminer.favor-group.ru;
# Dmitry Verkhoturov and Eugene Donich external address
allow 79.139.0.0/16;
Expand Down
6 changes: 4 additions & 2 deletions config/nginx/conf.d/cdn.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ map $http_origin $allow_origin {
}

server {
listen 443 http2 ssl;
listen 443 ssl;
listen 443 quic;

server_name static.cdn-favor-group.ru;

Expand All @@ -16,7 +17,8 @@ server {
}

server {
listen 443 http2 ssl;
listen 443 ssl;
listen 443 quic;

server_name dev.cdn-favor-group.ru;

Expand Down
3 changes: 2 additions & 1 deletion config/nginx/conf.d/dev-test.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
server {
listen 443 http2 ssl;
listen 443 ssl;
listen 443 quic;

server_name dev-test.favor-group.ru;

Expand Down
3 changes: 2 additions & 1 deletion config/nginx/conf.d/dev.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
server {
listen 443 http2 ssl;
listen 443 ssl;
listen 443 quic;

server_name dev.favor-group.ru;

Expand Down
4 changes: 3 additions & 1 deletion config/nginx/conf.d/hooks.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
server {
listen 443 http2 ssl;
listen 443 ssl;
listen 443 quic;

server_name hooks.favor-group.ru;
location / {
proxy_read_timeout 600;
Expand Down
15 changes: 6 additions & 9 deletions config/nginx/conf.d/prod.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
server {
listen 443 http2 reuseport ssl;
#listen 443 quic reuseport;
#add_header Alt-Svc 'h3=":443"; ma=86400';
listen 443 reuseport ssl;
listen 443 quic reuseport;

server_name favor-group.ru;

Expand All @@ -21,9 +20,8 @@ server {
}

server {
listen 443 http2 ssl;
#listen 443 quic reuseport;
#add_header Alt-Svc 'h3=":443"; ma=86400';
listen 443 ssl;
listen 443 quic;

server_name spb.favor-group.ru;

Expand All @@ -43,9 +41,8 @@ server {
}

server {
listen 443 http2 ssl;
#listen 443 quic reuseport;
#add_header Alt-Svc 'h3=":443"; ma=86400';
listen 443 ssl;
listen 443 quic;

server_name tula.favor-group.ru;

Expand Down
4 changes: 2 additions & 2 deletions config/nginx/conf.d/redirects.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# https www is a special case
server {
listen 443 ssl http2;
listen 443 ssl;
server_name www.favor-group.ru;
ssl_certificate /etc/nginx/letsencrypt/live/favor-group.ru/fullchain.pem;
ssl_certificate_key /etc/nginx/letsencrypt/live/favor-group.ru/privkey.pem;
Expand All @@ -25,7 +25,7 @@ server {
}

server {
listen 443 default_server ssl http2;
listen 443 default_server ssl;
ssl_certificate /etc/nginx/letsencrypt/live/favor-group.ru/fullchain.pem;
ssl_certificate_key /etc/nginx/letsencrypt/live/favor-group.ru/privkey.pem;
ssl_trusted_certificate /etc/nginx/letsencrypt/live/favor-group.ru/chain.pem;
Expand Down
11 changes: 7 additions & 4 deletions config/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ worker_processes auto;
error_log /var/log/nginx/other.error.log warn;
pid /var/run/nginx.pid;

load_module modules/ngx_http_brotli_filter_module.so;
load_module modules/ngx_http_brotli_static_module.so;
#load_module modules/ngx_http_brotli_filter_module.so;
#load_module modules/ngx_http_brotli_static_module.so;

events {
worker_connections 8192;
Expand Down Expand Up @@ -70,7 +70,8 @@ http {
map_hash_bucket_size 512;
# increase concurrency performance
keepalive_requests 1000;
http2_push_preload on;
http2 on;
ssl_early_data on;

map $remote_addr $not_logging {
default 1;
Expand Down Expand Up @@ -99,7 +100,7 @@ http {
ssl_dhparam /etc/nginx/letsencrypt/dhparams.pem;

# intermediate configuration
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers on;

Expand All @@ -110,6 +111,8 @@ http {

# HSTS (ngx_http_headers_module is required) (63072000 seconds)
add_header Strict-Transport-Security 'max-age=31536000; includeSubdomains; preload' always;
# http3
#add_header alt-svc 'h3=":443"; ma=86400';

# Reverse CloudFlare proxy
# DO NOT use CloudFlare in Russia, Yandex will ban you!
Expand Down
3 changes: 3 additions & 0 deletions config/nginx/security_headers.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ add_header Strict-Transport-Security 'max-age=31536000; includeSubdomains; prelo

# for the sake of better benchmark score
add_header Referrer-Policy same-origin;

# http3
#add_header alt-svc 'h3=":443"; ma=86400';
1 change: 1 addition & 0 deletions config/nginx/static-cdn.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ location ~* ^.+\.(xml|txt|jpeg|jpg|png|gif|bmp|ico|svg|tif|tiff|css|map|js|json|
expires max;
add_header Cache-Control public;
add_header Access-Control-Allow-Origin $allow_origin;
add_header alt-svc 'h3=":443"; ma=86400';
include security_headers.conf;
valid_referers none blocked favor-group.ru *.favor-group.ru *.cdn-favor-group.ru;
if ($invalid_referer) {
Expand Down

0 comments on commit 30febe5

Please sign in to comment.