main
1# This is based on (but heavily modified from) the example configuration
2# shipped in the nginx package in FreeBSD 15.1, so the license conditions from
3# that package may apply.
4
5worker_processes 1;
6
7load_module /usr/local/libexec/nginx/ngx_http_brotli_static_module.so;
8load_module /usr/local/libexec/nginx/ngx_http_zstd_static_module.so;
9
10events {
11 worker_connections 1024;
12}
13
14
15http {
16 include mime.types;
17 default_type application/octet-stream;
18
19 sendfile on;
20 #tcp_nopush on;
21
22 keepalive_timeout 65;
23
24 log_not_found off;
25
26 map_hash_max_size 65536;
27 map_hash_bucket_size 512;
28 map $uri $hash_etag {
29 default "";
30 include etag.map;
31 }
32 map $uri $hash_match_etag {
33 default "a file that isn't in our map";
34 include etag.map;
35 }
36
37 map $uri $cachecontrol {
38 default "public, s-maxage=31536000, stale-if-error=3600";
39 "~^/style\.min\..*\.css$" "public, max-age=31536000, s-maxage=31536000, stale-if-error=3600, immutable";
40 # hugo processed images have a hash
41 "~^.*_hu.*\.(jpg|jpeg|png|gif|webp|avif)$" "public, max-age=31536000, s-maxage=31536000, stale-if-error=3600, immutable";
42 # my forked gitmal makes lovely hash-named CSS files
43 "~^/git/.*/assets/common\..*.css" "public, max-age=31536000, s-maxage=31536000, stale-if-error=3600, immutable";
44 }
45
46 server {
47 listen 172.16.0.2:80 default_server;
48
49 location / {
50 gzip_vary on;
51 gzip_static on;
52 zstd_static on;
53 brotli_static on;
54 root /usr/local/www/blog;
55 index index.html;
56
57 # we override etags so we have to deal with matching them
58 if ($http_if_none_match = $hash_match_etag) {
59 return 304;
60 }
61
62 # should always be overridden below but just in case
63 # keep our security bits and bobs and give us a surrogate key to purge
64 add_header Surrogate-Key "blog-etag-missing";
65 add_header Last-Modified "";
66 add_header Content-Security-Policy "default-src 'none'; style-src 'self'; img-src 'self'; base-uri 'none'; require-trusted-types-for 'script';";
67 include client-side-security.inc;
68
69 etag off;
70 if ($hash_etag != "") {
71 add_header ETag $hash_etag always;
72 # In theory the s-maxage should cover most cases, the SIE is just
73 # to cover soft-purge followed by origin issue
74 add_header Cache-Control $cachecontrol;
75 add_header Surrogate-Key "blog";
76 # etag is enough, let's not confuse stuff with last-modified
77 add_header Last-Modified "";
78
79 # Content security policy
80 # Assumes no JS, which works fine atm but may one day require adjusting
81 add_header Content-Security-Policy "default-src 'none'; style-src 'self'; img-src 'self'; base-uri 'none'; require-trusted-types-for 'script';";
82 include client-side-security.inc;
83 }
84 }
85
86 location = /git {
87 return 301 https://www.intermittent.network/code/;
88 }
89
90 location = /git/ {
91 return 301 https://www.intermittent.network/code/;
92 }
93
94 location ^~ /git/ {
95 gzip_vary on;
96 gzip_static on;
97 zstd_static on;
98 brotli_static on;
99 root /usr/local/www/;
100 index index.html;
101
102 # we override etags so we have to deal with matching them
103 if ($http_if_none_match = $hash_match_etag) {
104 return 304;
105 }
106
107
108 add_header Content-Security-Policy "default-src 'none'; style-src 'self'; img-src 'self'; base-uri 'none'; require-trusted-types-for 'script';";
109 include client-side-security.inc;
110
111 etag off;
112 if ($hash_etag != "") {
113 add_header ETag $hash_etag always;
114 add_header Cache-Control $cachecontrol;
115 add_header Surrogate-Key "git";
116 add_header Last-Modified "";
117 add_header Content-Security-Policy "default-src 'none'; style-src 'self'; img-src 'self'; base-uri 'none'; require-trusted-types-for 'script';";
118 include client-side-security.inc;
119 }
120 }
121
122 location ^~ /cgi-bin/ {
123 root /usr/local/www/;
124
125 # don't set a default CSP, leave that to the scripts on the basis of what they use,
126 # but we can have the others.
127 include client-side-security.inc;
128
129 # Point to the FreeBSD fcgiwrap Unix socket
130 fastcgi_pass unix:/var/run/fcgiwrap/fcgiwrap.sock;
131
132 # Include standard FastCGI parameters included with FreeBSD's Nginx package
133 include fastcgi_params;
134
135 # Script execution parameters
136 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
137 }
138
139 # redirect server error pages to the static page /50x.html
140 #
141 error_page 500 502 503 504 /50x.html;
142 location = /50x.html {
143 root /usr/local/www/nginx-dist;
144 internal;
145 }
146
147 error_page 404 /404.html;
148 location = /404.html {
149 root /usr/local/www/blog;
150 internal;
151 etag off;
152 add_header Cache-Control $cachecontrol;
153 add_header Surrogate-Key "404";
154 add_header Last-Modified "";
155 add_header Content-Security-Policy "default-src 'none'; style-src 'self'; img-src 'self'; base-uri 'none'; require-trusted-types-for 'script';";
156 include client-side-security.inc;
157 }
158 }
159
160}