Skip to content

Commit a0dc784

Browse files
committed
feat: add default compression and cache config
add gzip config add strict asset cache configs update nginx-proxy image version
1 parent 12a962b commit a0dc784

File tree

6 files changed

+969
-5
lines changed

6 files changed

+969
-5
lines changed

README.md

+26
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,28 @@
11
# nginx-proxy
2+
23
Repository for dockerized nginx proxy deployable on VPS
4+
5+
> Important
6+
> When updating nginx-proxy, always update `nginx.tmpl` file as well. Instructions on how to do that are in "Working with nginx.tmpl" section below.
7+
8+
## Working with nginx.tmpl
9+
10+
1. Create `nginx.new.tmpl` file and copy over [`nginx.tmpl` content from `nginx-proxy` repo](https://github.com/nginx-proxy/nginx-proxy/blob/main/nginx.tmpl) into it and `nginx.tmpl` in this repo.
11+
12+
2. Apply changes from `nginx.tmpl.patch` into `nginx.tmpl`.
13+
14+
```bash
15+
patch nginx.tmpl nginx.tmpl.patch
16+
```
17+
18+
> If the command above does not work it's possible that contents of `nginx.tmpl` have changed in new version of `nginx-proxy`. In such case you'll need to apply those changes manually.
19+
20+
3. Make other changes you need in `nginx.tmpl` file.
21+
22+
4. Generate a new `.patch` file.
23+
24+
```bash
25+
diff -u nginx.new.tmpl nginx.tmpl > nginx.tmpl.patch
26+
```
27+
28+
5. Now you can safely remove `nginx.new.tmpl` file.

conf.d/compression.conf

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# ----------------------------------------------------------------------
2+
# | Compression |
3+
# ----------------------------------------------------------------------
4+
5+
# Brotli
6+
# https://github.com/google/ngx_brotli?tab=readme-ov-file#configuration-directives
7+
# brotli on;
8+
9+
# Compression level (1-11).
10+
# We do not change the default compression level, which is 6.
11+
# Default: 6
12+
# brotli_comp_level 6;
13+
14+
# Don't compress anything that's already small and unlikely to shrink much if at
15+
# all.
16+
# Default: 20
17+
# brotli_min_length 256;
18+
19+
# Compress all output labeled with one of the following MIME-types.
20+
# `text/html` is always compressed by gzip module.
21+
# Default: text/html
22+
# brotli_types
23+
# application/atom+xml
24+
# application/geo+json
25+
# application/javascript
26+
# application/x-javascript
27+
# application/json
28+
# application/ld+json
29+
# application/manifest+json
30+
# application/rdf+xml
31+
# application/rss+xml
32+
# application/vnd.ms-fontobject
33+
# application/wasm
34+
# application/x-web-app-manifest+json
35+
# application/xhtml+xml
36+
# application/xml
37+
# font/eot
38+
# font/otf
39+
# font/ttf
40+
# image/bmp
41+
# image/svg+xml
42+
# image/vnd.microsoft.icon
43+
# image/x-icon
44+
# text/cache-manifest
45+
# text/calendar
46+
# text/css
47+
# text/javascript
48+
# text/markdown
49+
# text/plain
50+
# text/xml
51+
# text/vcard
52+
# text/vnd.rim.location.xloc
53+
# text/vtt
54+
# text/x-component
55+
# text/x-cross-domain-policy;
56+
57+
# gzip
58+
# https://docs.nginx.com/nginx/admin-guide/dynamic-modules/brotli/
59+
60+
# Enable gzip compression.
61+
# Default: off
62+
gzip on;
63+
64+
# Compression level (1-9).
65+
# 5 is a perfect compromise between size and CPU usage, offering about 75%
66+
# reduction for most ASCII files (almost identical to level 9).
67+
# Default: 1
68+
gzip_comp_level 5;
69+
70+
# Don't compress anything that's already small and unlikely to shrink much if at
71+
# all (the default is 20 bytes, which is bad as that usually leads to larger
72+
# files after gzipping).
73+
# Default: 20
74+
gzip_min_length 256;
75+
76+
# Compress data even for clients that are connecting to us via proxies,
77+
# identified by the "Via" header (required for CloudFront).
78+
# Default: off
79+
gzip_proxied any;
80+
81+
# Tell proxies to cache both the gzipped and regular version of a resource
82+
# whenever the client's Accept-Encoding capabilities header varies;
83+
# Avoids the issue where a non-gzip capable client (which is extremely rare
84+
# today) would display gibberish if their proxy gave them the gzipped version.
85+
# Default: off
86+
gzip_vary on;
87+
88+
# Compress all output labeled with one of the following MIME-types.
89+
# `text/html` is always compressed by gzip module.
90+
# Default: text/html
91+
gzip_types
92+
application/atom+xml
93+
application/geo+json
94+
application/javascript
95+
application/x-javascript
96+
application/json
97+
application/ld+json
98+
application/manifest+json
99+
application/rdf+xml
100+
application/rss+xml
101+
application/vnd.ms-fontobject
102+
application/wasm
103+
application/x-web-app-manifest+json
104+
application/xhtml+xml
105+
application/xml
106+
font/eot
107+
font/otf
108+
font/ttf
109+
image/bmp
110+
image/svg+xml
111+
image/vnd.microsoft.icon
112+
image/x-icon
113+
text/cache-manifest
114+
text/calendar
115+
text/css
116+
text/javascript
117+
text/markdown
118+
text/plain
119+
text/xml
120+
text/vcard
121+
text/vnd.rim.location.xloc
122+
text/vtt
123+
text/x-component
124+
text/x-cross-domain-policy;

docker-compose.yml

+3-5
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ version: '2'
77

88
services:
99
nginx-proxy:
10-
image: nginxproxy/nginx-proxy:1.3.1-alpine
1110
container_name: nginx-proxy
11+
build:
12+
context: .
13+
dockerfile: docker/nginx-proxy/Dockerfile
1214
environment:
1315
TRUST_DOWNSTREAM_PROXY: "false"
1416
ports:
1517
- "80:80"
1618
- "443:443"
1719
volumes:
18-
- conf:/etc/nginx/conf.d
19-
- vhost:/etc/nginx/vhost.d
2020
- html:/usr/share/nginx/html
2121
- certs:/etc/nginx/certs:ro
2222
- /var/run/docker.sock:/tmp/docker.sock:ro
@@ -48,8 +48,6 @@ services:
4848
- nginx-proxy
4949

5050
volumes:
51-
conf:
52-
vhost:
5351
html:
5452
certs:
5553
acme:

docker/nginx-proxy/Dockerfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM nginxproxy/nginx-proxy:1.5.1-alpine
2+
3+
COPY conf.d/* /etc/nginx/conf.d/
4+
COPY nginx.tmpl /app/

0 commit comments

Comments
 (0)