strava-frontend/nginx.conf

90 lines
2.9 KiB
Nginx Configuration File

worker_processes auto;
pid /tmp/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
gzip on;
gzip_comp_level 6;
gzip_vary on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/rss+xml image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype;
server {
listen 80;
server_name localhost;
# SSR routes (search bots + guests get real HTML)
location ~ ^/(explore|routes|sitemap\.xml|robots\.txt)$ {
proxy_pass http://127.0.0.1:3001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Cookie $http_cookie;
}
# Public workout detail — SSR
location ~ ^/public/workouts/ {
proxy_pass http://127.0.0.1:3001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Cookie $http_cookie;
}
# Landing page — always SSR (server checks auth cookie, redirects if present)
location = / {
proxy_pass http://127.0.0.1:3001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Cookie $http_cookie;
}
# SPA whitelist — client-side routes
location ~ ^/(workouts|auth|preferences|404)(/|$) {
root /usr/share/nginx/html;
try_files $uri /index.html;
}
# Static public files (favicon, images, manifest, fonts)
location ~* \.(png|jpe?g|gif|ico|svg|webp|avif|webmanifest|eot|ttf|woff2?|otf)$ {
root /usr/share/nginx/html;
expires 7d;
add_header Cache-Control "public";
}
# Catch-all → SSR proxy (unknown paths get a 404 from SSR)
location / {
proxy_pass http://127.0.0.1:3001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Cookie $http_cookie;
}
# Static assets
location /assets/ {
root /usr/share/nginx/html;
expires 30d;
add_header Cache-Control "public, immutable";
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ /\. {
deny all;
}
}
}