# Include this file from OpenResty's http block. The Compose service listens only # on 127.0.0.1:18080, so clients cannot bypass these controls. map $http_upgrade $connection_upgrade { default upgrade; '' close; } limit_req_zone $binary_remote_addr zone=account_api:10m rate=20r/s; limit_req_zone $binary_remote_addr zone=invite_page:10m rate=5r/s; limit_req_status 429; upstream osg_account_server { server 127.0.0.1:18080; keepalive 32; } server { listen 80; listen [::]:80; server_name account.osglab.com; return 308 https://$host$request_uri; } server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name account.osglab.com; ssl_certificate /www/server/panel/vhost/cert/account.osglab.com/fullchain.pem; ssl_certificate_key /www/server/panel/vhost/cert/account.osglab.com/privkey.pem; ssl_protocols TLSv1.2 TLSv1.3; ssl_session_timeout 1d; ssl_session_cache shared:account_tls:10m; # Request client certificates at the shared TLS edge without requiring them # for mobile APIs. Only the dedicated admin CA is trusted for verification. ssl_client_certificate /www/server/openresty/conf/mtls/admin-client-ca.pem; ssl_verify_client optional; ssl_verify_depth 2; # An invalid certificate is rejected before location processing; normalize # that TLS verification failure so it does not reveal the protected surface. error_page 495 =404 @client_certificate_not_found; client_max_body_size 21m; server_tokens off; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; add_header X-Content-Type-Options "nosniff" always; add_header X-Frame-Options "DENY" always; add_header Referrer-Policy "no-referrer" always; # Internal-only endpoints remain unavailable through this public vhost. location ~ ^/internal(?:/|$) { return 404; } # Always forward administrative paths to Ktor. Ktor decides whether mTLS is # required from ADMIN_MTLS_REQUIRED, while this edge overwrites the trust # signal so clients cannot spoof successful certificate verification. location ~ ^/(?:admin|v1/admin)(?:/|$) { client_max_body_size 32k; limit_req zone=account_api burst=40 nodelay; # Defining a location-level header disables inheritance from the server # block, so repeat the security headers explicitly. add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; add_header X-Content-Type-Options "nosniff" always; add_header X-Frame-Options "DENY" always; add_header Referrer-Policy "no-referrer" always; add_header Content-Security-Policy "default-src 'self'; base-uri 'none'; frame-ancestors 'none'; form-action 'self'; object-src 'none'; script-src 'self'; style-src 'self'; connect-src 'self'" always; add_header Cache-Control "no-store" always; proxy_pass http://osg_account_server; proxy_http_version 1.1; 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 https; proxy_set_header X-Request-ID $request_id; proxy_set_header X-OSG-mTLS-Verified $ssl_client_verify; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_hide_header Server; proxy_request_buffering off; proxy_buffering off; proxy_cache off; proxy_read_timeout 360s; proxy_send_timeout 360s; } location @client_certificate_not_found { return 404; } location / { limit_req zone=account_api burst=40 nodelay; proxy_pass http://osg_account_server; proxy_http_version 1.1; 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 https; proxy_set_header X-Request-ID $request_id; # Suppress spoofed trust signals on every non-admin request. proxy_set_header X-OSG-mTLS-Verified ""; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_hide_header Server; proxy_request_buffering off; proxy_buffering off; proxy_cache off; proxy_read_timeout 360s; proxy_send_timeout 360s; } } server { listen 80; listen [::]:80; server_name osglab.com www.osglab.com; return 308 https://osglab.com$request_uri; } server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name osglab.com www.osglab.com; ssl_certificate /www/server/panel/vhost/cert/osglab.com/fullchain.pem; ssl_certificate_key /www/server/panel/vhost/cert/osglab.com/privkey.pem; ssl_protocols TLSv1.2 TLSv1.3; server_tokens off; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; add_header X-Content-Type-Options "nosniff" always; add_header Referrer-Policy "no-referrer" always; location = /.well-known/apple-app-site-association { access_log off; proxy_pass http://osg_account_server; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto https; } location = /apple-app-site-association { access_log off; proxy_pass http://osg_account_server; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto https; } # Invitation codes are bearer-like values and must not appear in access logs. location ^~ /i/ { access_log off; limit_req zone=invite_page burst=10 nodelay; proxy_pass http://osg_account_server; proxy_http_version 1.1; 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 https; proxy_set_header X-Request-ID $request_id; proxy_hide_header Server; proxy_buffering off; proxy_cache off; } # Keep the existing 1Panel site root for all non-invitation pages. root /www/wwwroot/osglab.com; location / { try_files $uri $uri/ =404; } }