new-site/infra/ansible/roles/nginx/templates/pw-api-tls.conf.j2
justin f8cd37ac8c Initial commit — Performance West telecom compliance platform
Includes: API (Express/TypeScript), Astro site, Python workers,
document generators, FCC compliance tools, Canada CRTC formation,
Ansible infrastructure, and deployment scripts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-27 06:54:22 -05:00

75 lines
2.4 KiB
Django/Jinja

# {{ ansible_managed }}
# HTTPS config for api.performancewest.net
# Rate limiting zone
limit_req_zone $binary_remote_addr zone=api_limit:10m rate=10r/s;
# Redirect HTTP -> HTTPS
server {
listen 80;
server_name api.performancewest.net;
location /.well-known/acme-challenge/ {
root {{ certbot_webroot }};
}
location / {
return 301 https://api.performancewest.net$request_uri;
}
}
# API server
server {
listen 443 ssl;
http2 on;
server_name api.performancewest.net;
ssl_certificate /etc/letsencrypt/live/api.performancewest.net/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/api.performancewest.net/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
include /etc/nginx/snippets/pw-security.conf;
# CORS headers
add_header Access-Control-Allow-Origin "https://performancewest.net" always;
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS" always;
add_header Access-Control-Allow-Headers "Authorization, Content-Type, Accept" always;
add_header Access-Control-Max-Age 86400 always;
location / {
# Handle CORS preflight
if ($request_method = OPTIONS) {
add_header Access-Control-Allow-Origin "https://performancewest.net";
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS";
add_header Access-Control-Allow-Headers "Authorization, Content-Type, Accept";
add_header Access-Control-Max-Age 86400;
add_header Content-Length 0;
add_header Content-Type text/plain;
return 204;
}
# Rate limiting
limit_req zone=api_limit burst=20 nodelay;
limit_req_status 429;
proxy_pass http://127.0.0.1:{{ api_port }};
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 X-Forwarded-Proto $scheme;
proxy_connect_timeout 10s;
proxy_send_timeout 30s;
proxy_read_timeout 30s;
}
location /.well-known/acme-challenge/ {
root {{ certbot_webroot }};
}
}