39 lines
1.5 KiB
Plaintext
39 lines
1.5 KiB
Plaintext
# ---------------------------------------------------------------------------
|
|
# Nginx static sitemap file serving
|
|
# ---------------------------------------------------------------------------
|
|
# Include this snippet inside your `server {}` block BEFORE the main
|
|
# `location /` (or `location ~ \.php$`) block so nginx serves the pre-built
|
|
# static XML files without ever touching PHP/FPM.
|
|
#
|
|
# The GenerateSitemapsCommand writes these files on a schedule (every 6 h):
|
|
# public/sitemap.xml <- root sitemap index
|
|
# public/sitemaps/{name}.xml <- per-family / per-shard documents
|
|
#
|
|
# When a file has not been generated yet (first deploy, cold start) the
|
|
# request falls through to @php and Laravel's SitemapController builds it
|
|
# live on the first hit.
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# Root sitemap index
|
|
location = /sitemap.xml {
|
|
# Serve the static file if it exists; otherwise fall through to PHP.
|
|
try_files $uri @php;
|
|
|
|
# Instruct downstream caches / crawlers how long the file is fresh.
|
|
add_header Cache-Control "public, max-age=21600" always; # 6 h
|
|
add_header Content-Type "application/xml; charset=UTF-8" always;
|
|
|
|
# Optional: let nginx set a strong ETag automatically (default behaviour).
|
|
etag on;
|
|
}
|
|
|
|
# Per-family / per-shard sitemap documents
|
|
location ~ ^/sitemaps/[A-Za-z0-9_\-]++\.xml$ {
|
|
try_files $uri @php;
|
|
|
|
add_header Cache-Control "public, max-age=21600" always; # 6 h
|
|
add_header Content-Type "application/xml; charset=UTF-8" always;
|
|
|
|
etag on;
|
|
}
|