IIS now sends www.andreaslop.nl to https://andreaslop.nl in one step, so monitoring and search engines see a single address. The go-live steps check the redirect and wait for the privacy statement, and the readiness checklist lists what is left for the go-live. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
177 lines
7.0 KiB
TypeScript
177 lines
7.0 KiB
TypeScript
// Genereert de webserverconfiguratie voor test (nginx op de Raspberry Pi) en
|
|
// productie (IIS bij de webhoster) uit dezelfde securityheaders als de Vite
|
|
// dev- en preview-server. Zo bestaat de headerset maar op één plek.
|
|
// Schrijven: `pnpm server-config`. Een test controleert dat de bestanden in
|
|
// deploy/ gelijk zijn aan wat deze functies opleveren.
|
|
import { securityHeaders } from './securityHeaders.ts';
|
|
|
|
const generatedNotice =
|
|
'Gegenereerd door web/config/serverConfig.ts (pnpm server-config). Niet handmatig aanpassen.';
|
|
|
|
const xmlAttribute = (value: string) =>
|
|
value
|
|
.replace(/&/g, '&')
|
|
.replace(/"/g, '"')
|
|
.replace(/</g, '<')
|
|
.replace(/>/g, '>');
|
|
|
|
// De enige productiehost: www stuurt hierheen door, zodat monitoring (alleen
|
|
// op deze hostname) en zoekmachines één adres zien
|
|
export const productionHost = 'andreaslop.nl';
|
|
|
|
// IIS (productie): www-doorverwijzing, security headers, HTTPS-redirect,
|
|
// SPA-fallback en caching. De www-regel staat vóór HTTPS, zodat
|
|
// http://www. in één stap op https://andreaslop.nl uitkomt.
|
|
// Bestanden in /assets hebben een hash in de naam en mogen lang gecachet
|
|
// worden; index.html nooit, zodat een nieuwe release direct zichtbaar is.
|
|
export function iisWebConfig(): string {
|
|
const headers = Object.entries(securityHeaders('production'))
|
|
.map(
|
|
([name, value]) =>
|
|
` <add name="${name}" value="${xmlAttribute(value)}" />`,
|
|
)
|
|
.join('\n');
|
|
|
|
return `<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- ${generatedNotice} -->
|
|
<configuration>
|
|
<system.webServer>
|
|
<rewrite>
|
|
<rules>
|
|
<rule name="www naar ${productionHost}" stopProcessing="true">
|
|
<match url="(.*)" />
|
|
<conditions>
|
|
<add input="{HTTP_HOST}" pattern="^www\\.${productionHost.replace(/\./g, '\\.')}$" />
|
|
</conditions>
|
|
<action type="Redirect" url="https://${productionHost}/{R:1}" redirectType="Permanent" />
|
|
</rule>
|
|
<rule name="HTTPS" stopProcessing="true">
|
|
<match url="(.*)" />
|
|
<conditions>
|
|
<add input="{HTTPS}" pattern="^OFF$" />
|
|
</conditions>
|
|
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
|
|
</rule>
|
|
<rule name="SPA fallback" stopProcessing="true">
|
|
<match url=".*" />
|
|
<conditions logicalGrouping="MatchAll">
|
|
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
|
|
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
|
|
</conditions>
|
|
<action type="Rewrite" url="/index.html" />
|
|
</rule>
|
|
</rules>
|
|
</rewrite>
|
|
<httpProtocol>
|
|
<customHeaders>
|
|
<remove name="X-Powered-By" />
|
|
${headers}
|
|
</customHeaders>
|
|
</httpProtocol>
|
|
<staticContent>
|
|
<remove fileExtension=".woff2" />
|
|
<mimeMap fileExtension=".woff2" mimeType="font/woff2" />
|
|
<clientCache cacheControlMode="DisableCache" />
|
|
</staticContent>
|
|
</system.webServer>
|
|
<location path="assets">
|
|
<system.webServer>
|
|
<staticContent>
|
|
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
|
|
</staticContent>
|
|
</system.webServer>
|
|
</location>
|
|
</configuration>
|
|
`;
|
|
}
|
|
|
|
// nginx (test): dezelfde headers, plus noindex zodat de testsite nooit in
|
|
// zoekmachines komt. nginx erft add_header niet als een location er zelf een
|
|
// zet, daarom staan de headers in elk location-blok.
|
|
export function nginxTestConf(): string {
|
|
const headers = [
|
|
...Object.entries(securityHeaders('production')).map(
|
|
([name, value]) => `add_header ${name} "${value}" always;`,
|
|
),
|
|
'add_header X-Robots-Tag "noindex, nofollow" always;',
|
|
];
|
|
const block = (indent: string, extra: string[] = []) =>
|
|
[...headers, ...extra].map((line) => indent + line).join('\n');
|
|
|
|
return `# ${generatedNotice}
|
|
# Test-omgeving op de Raspberry Pi, achter de reverse-proxy-Pi (die TLS afhandelt
|
|
# met certbot). De proxy moet de Host-header doorgeven (proxy_set_header Host
|
|
# $host), anders kiest nginx hier het standaardblok (WordPress).
|
|
# Eigen server-blok naast de WordPress-site: bewust geen default_server, zodat
|
|
# dit blok alleen de testhostname beantwoordt.
|
|
# Pas server_name en root aan aan de server; de rest komt uit de generator.
|
|
server {
|
|
listen 80;
|
|
server_name test.andreaslop.nl;
|
|
root /var/www/html/andreaslop-test;
|
|
index index.html;
|
|
|
|
# Achter de reverse proxy: doorverwijzingen relatief houden, anders stuurt
|
|
# nginx naar zijn eigen http://-adres in plaats van de https-hostname
|
|
absolute_redirect off;
|
|
|
|
${block(' ', ['add_header Cache-Control "no-cache" always;'])}
|
|
|
|
# Testsite nooit indexeren
|
|
location = /robots.txt {
|
|
${block(' ')}
|
|
default_type text/plain;
|
|
return 200 "User-agent: *\\nDisallow: /\\n";
|
|
}
|
|
|
|
# Bestanden met een hash in de naam: lang cachen
|
|
location /assets/ {
|
|
${block(' ', ['add_header Cache-Control "public, max-age=31536000, immutable" always;'])}
|
|
try_files $uri =404;
|
|
}
|
|
|
|
# SPA-fallback: onbekende paden krijgen index.html (de router toont de 404).
|
|
# =404 aan het eind: zonder index.html (lege map) een 404 in plaats van een
|
|
# doorverwijzingslus die nginx als 500 afbreekt
|
|
location / {
|
|
${block(' ', ['add_header Cache-Control "no-cache" always;'])}
|
|
try_files $uri $uri/ /index.html =404;
|
|
}
|
|
}
|
|
`;
|
|
}
|
|
|
|
// nginx op de reverse-proxy-Pi (test): alleen HTTP. certbot voegt daarna
|
|
// HTTPS en de redirect toe (certbot --nginx -d test.andreaslop.nl). Geen
|
|
// security headers hier: die zet de hosting-Pi al, dubbel geeft dubbele headers.
|
|
// Intern adres van de hosting-Pi (waar het testblok en WordPress draaien)
|
|
const hostingPiAddress = '192.168.1.103';
|
|
|
|
export function nginxProxyConf(): string {
|
|
return `# ${generatedNotice}
|
|
# Reverse proxy voor de testsite naar de hosting-Pi. certbot past dit bestand
|
|
# aan voor HTTPS; kopieer het daarna dus niet opnieuw zonder certbot opnieuw te
|
|
# draaien.
|
|
server {
|
|
listen 80;
|
|
server_name test.andreaslop.nl;
|
|
|
|
location / {
|
|
proxy_pass http://${hostingPiAddress};
|
|
# Verplicht: de hosting-Pi kiest op basis van de hostname tussen het
|
|
# testblok en WordPress
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
}
|
|
}
|
|
`;
|
|
}
|
|
|
|
export const serverConfigFiles = {
|
|
'deploy/iis/web.config': iisWebConfig,
|
|
'deploy/nginx/andreaslop-test.conf': nginxTestConf,
|
|
'deploy/nginx/test.andreaslop.nl.proxy.conf': nginxProxyConf,
|
|
} as const;
|