Repository navigation
Expand file tree
/
Copy pathnginx.conf
More file actions
181 lines (159 loc) · 10.7 KB
/
Copy pathnginx.conf
File metadata and controls
181 lines (159 loc) · 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
worker_processes 2;
events {
worker_connections 1024;
}
pid /tmp/nginx.pid;
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
# Allow request headers up to 32k (matches the Cloud Run/GFE ceiling).
# Marketing trackers set large cookies on .chainguard.dev that are sent to
# every subdomain; nginx's default 8k buffer rejects those requests with
# "400 Request Header Or Cookie Too Large".
large_client_header_buffers 4 32k;
gzip on;
gzip_disable "msie6"; # Disable comnpression on really old Internet Explorer
gzip_comp_level 6; # Moderate compression level
gzip_min_length 256; # Don't zip really small files
gzip_buffers 16 8k;
gzip_proxied any;
gzip_types
text/plain
text/css
text/js
text/xml
text/javascript
application/javascript
application/json
application/xml
application/rss+xml
image/svg+xml;
# Exact-path rules from data/redirects.yaml go into the redirect map's
# hash. The default bucket, 64 bytes on most CPUs, cannot hold a long
# docs path, and nginx refuses to start. Regex rules are not hashed.
# This must come before the first map block.
map_hash_bucket_size 128;
# Key the redirect map on the request path with the query string removed.
# $request_uri carries the query, and nearly every rule below ends in $1,
# so matching $request_uri put the query inside $redirect_url -- and the
# rewrite that applies the map appends the request arguments again,
# emitting "?utm_source=x?utm_source=x" (DOCS-187). A query-free key keeps
# $redirect_url query-free, so the append becomes the only source of a
# query on the Location, and it lands exactly once.
#
# $uri is the obvious key and is wrong: it is percent-decoded, so a request
# for %3F would put a literal "?" back into $redirect_url and reintroduce
# the duplication.
map $request_uri $request_path {
"~^(?<path_without_query>[^?]*)" $path_without_query;
}
# Every redirect rule is generated by Hugo into public/_aliases, which the
# Dockerfile copies to /etc/nginx/aliases: first a rule for every page
# alias, longest first, then the hand-written rules from
# data/redirects.yaml. Add a redirect there or as a page alias, not here.
# The Vercel preview's routing table is generated from the same rules
# (layouts/partials/redirect-rules.html).
#
# nginx takes the first regex in a map that matches, so every alias rule
# beats every hand-written rule. A section root that carries an alias
# claims its whole subtree and shadows anything more specific in
# data/redirects.yaml. Put that exception on the destination page's own
# "aliases:" instead: the longest-first sort ranks it above the section.
map $request_path $redirect_url {
default "";
include aliases;
}
# The docs now live at www.chainguard.dev/docs, so this server only
# redirects: every request goes to the same page there, in one hop.
#
# A path the alias map knows goes straight to its current page instead
# of through its old address. The new site has no trailing slashes, so
# one is dropped here, which saves another redirect. An absolute target,
# such as a page Marketing took over on www, is used as it is. None of
# these values carries a query string; the "return" below adds it.
map $request_path $docs_request_path {
"~^(?<path_without_slash>.*?)/?$" $path_without_slash;
}
map $redirect_url $docs_url {
"" https://www.chainguard.dev/docs$docs_request_path;
"~^https://" $redirect_url;
"~^(?<alias_target>.*?)/?$" https://www.chainguard.dev/docs$alias_target;
}
server {
listen 8080;
server_name localhost;
root /usr/share/nginx/html/;
# Send every request to www.chainguard.dev/docs (see $docs_url).
# "return" appends nothing, so $is_args$args carries the query
# string, exactly once. Browsers may cache a 301 indefinitely;
# max-age limits that to a day, so a rollback reaches readers.
# The rewrites and locations below no longer run; they stay so a
# revert restores the site as it was.
add_header Cache-Control "max-age=86400" always;
return 301 $docs_url$is_args$args;
# process $request_path -> $redirect_url if url is absolute
if ($redirect_url ~ ^https://) {
rewrite ^(.*)$ $redirect_url permanent;
}
# process $request_path -> $redirect_url, preserving https, and ensure URLs don't have any ports in them
if ($redirect_url != "") {
rewrite ^(.*)$ https://$http_host$redirect_url permanent;
}
# Redirect URLs without trailing slash to URLs with trailing slash
# This ensures images in Hugo content directories display correctly
#
# "return" does not append the request arguments the way "rewrite"
# does, so $is_args$args carries the query string across this hop.
# Without it a campaign URL lost its parameters here (DOCS-187).
#
# The scheme is hardcoded for the same reason the redirect map above
# hardcodes it: Cloud Run terminates TLS at the load balancer, so
# $scheme is "http" and emitting it downgraded every one of these
# redirects to plaintext.
location ~ ^([^.]*[^/])$ {
if (-d $request_filename) {
return 301 https://$host$uri/$is_args$args;
}
}
# Serve .md versions of pages for LLM access
location ~ ^(.+)\.md$ {
default_type "text/markdown";
try_files $uri $1/index.md =404;
}
location / {
index index.html index.htm;
try_files $uri $uri/index.html =404;
}
# This location matches every directory URL, so it serves every content
# page. A location that sets any add_header of its own drops every
# add_header inherited from the server block below, so the security
# headers are repeated here; without them no content page carried
# any (DOCS-219). Keep these three in step with the server block.
#
# The Content-Security-Policy is deliberately left out. Enforcing it
# on pages blocks the Kapa widget and Marketing's tag-manager tags;
# DOCS-219 records what has to be agreed first.
location ~* /(index.html)?$ {
add_header Cache-Control "public, max-age=300, stale-while-revalidate=300";
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "0" always;
}
# Security headers including CSP for Google Tag Manager
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "0" always;
add_header Content-Security-Policy "default-src 'self'; frame-src 'self' https://www.googletagmanager.com https://player.vimeo.com https://www.youtube.com https://www.youtube-nocookie.com https://platform.twitter.com https://syndication.twitter.com https://visualization-ui.chainguard.app https://www.googletagmanager.com https://app.qualified.com www.google.com https://hcaptcha.com https://*.hcaptcha.com; style-src 'self' 'unsafe-inline' https://tagmanager.google.com https://www.googletagmanager.com https://googletagmanager.com cdn.jsdelivr.net https://fonts.googleapis.com https://unpkg.com https://hcaptcha.com https://*.hcaptcha.com; form-action 'self'; font-src 'self' https://fonts.googleapis.com https://fonts.gstatic.com https://cdn.jsdelivr.net; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://www.googletagmanager.com https://tagmanager.google.com https://googletagmanager.com *.googleapis.com cdn.jsdelivr.net *.googletagmanager.com https://www.google-analytics.com https://analytics.google.com https://snap.licdn.com https://unpkg.com https://csp.withgoogle.com https://play.google.com https://www.google.com https://www.redditstatic.com http://js.hs-scripts.com https://tag.clearbitscripts.com https://j.6sc.co https://tracking.g2crowd.com https://tag.unifyintent.com https://static.reo.dev https://googleads.g.doubleclick.net https://js.qualified.com https://js.hscollectedforms.net https://js.hubspot.com https://js.hsadspixel.net https://js.hs-banner.com https://js.hs-analytics.net https://x.clearbitjs.com https://js.zi-scripts.com https://cdn.amplitude.com widget.kapa.ai www.google.com https://hcaptcha.com https://*.hcaptcha.com https://*.algolia.net https://*.algolianet.com; connect-src 'self' https://www.googletagmanager.com https://tagmanager.google.com https://googletagmanager.com *.google-analytics.com *.googletagmanager.com https://analytics.google.com https://region1.google-analytics.com https://www.google-analytics.com https://px.ads.linkedin.com https://px4.ads.linkedin.com https://storage.googleapis.com https://packages.wolfi.dev https://script.google.com https://script.googleusercontent.com https://csp.withgoogle.com https://play.google.com *.googleapis.com https://www.google.com https://stats.g.doubleclick.net https://api.unifyintent.com https://api.reo.dev https://pixel-config.reddit.com https://www.redditstatic.com https://conversions-config.reddit.com https://ipv6.6sc.co https://static.hsappstatic.net https://app.qualified.com wss://ws6.qualified.com https://api.hubapi.com https://app.clearbit.com https://forms.hscollectedforms.net https://cta-service-cms2.hubspot.com https://js.zi-scripts.com https://ws.zoominfo.com https://x.clearbitjs.com https://js.hs-banner.com https://api2.amplitude.com https://api.amplitude.com proxy.kapa.ai kapa-widget-proxy-la7dkmplpq-uc.a.run.app metrics.kapa.ai https://hcaptcha.com https://*.hcaptcha.com https://*.algolia.net https://*.algolianet.com https://*.algolia.io; img-src 'self' 'unsafe-inline' https://ssl.gstatic.com https://storage.googleapis.com https://www.googletagmanager.com https://googletagmanager.com https://www.google-analytics.com https://analytics.google.com https://px.ads.linkedin.com https://px4.ads.linkedin.com https://www.google.com data: https://alb.reddit.com http://b.6sc.co https://forms.hsforms.com https://perf-na1.hsforms.com https://track.hubspot.com https://raw.githubusercontent.com; worker-src 'self' blob:; base-uri 'self';" always;
# use hugo's built in 404 page for now
error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
error_log stderr notice;