mnemo_cards/mnemo_cards_web_v2/deploy/vscode-nginx.conf

142 lines
4.8 KiB
Text
Raw Permalink Normal View History

2025-11-19 17:37:43 +00:00
# Note: Default server blocks are defined in forgejo configuration
# This configuration only handles vscode.mnemo-cards.online domain
server {
listen 80;
server_name vscode.mnemo-cards.online;
# Redirect HTTP to HTTPS
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
server_name vscode.mnemo-cards.online;
# SSL configuration - Let's Encrypt
ssl_certificate /etc/letsencrypt/live/vscode.mnemo-cards.online/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/vscode.mnemo-cards.online/privkey.pem;
# Fallback to self-signed certificates if Let's Encrypt fails
# ssl_certificate /etc/ssl/certs/nginx-selfsigned-vscode.crt;
# ssl_certificate_key /etc/ssl/private/nginx-selfsigned-vscode.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off;
# Client upload size limit (for large file uploads, git push, etc)
client_max_body_size 100M;
# Security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
2025-11-22 19:06:27 +00:00
# Static files - no rate limiting (VSCode loads many files simultaneously)
location ~ ^/(static|out|node_modules|_next)/ {
# No rate limiting for static files
proxy_pass http://127.0.0.1:8443;
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;
# Cache static files
proxy_cache_valid 200 1h;
add_header Cache-Control "public, max-age=3600";
# Timeout settings
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}
# Static file extensions - no rate limiting
location ~ \.(js|css|woff|woff2|ttf|eot|png|jpg|jpeg|gif|svg|ico|webp|map|json)$ {
# No rate limiting for static file extensions
proxy_pass http://127.0.0.1:8443;
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;
# Cache static files
proxy_cache_valid 200 1h;
add_header Cache-Control "public, max-age=3600";
# Timeout settings
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}
2025-11-19 17:37:43 +00:00
# Special rate limiting for login attempts
location /login {
# Strict rate limiting for login
limit_req zone=vscode_login burst=2 nodelay;
limit_req_status 429;
2025-11-19 19:59:53 +00:00
proxy_pass http://127.0.0.1:8443;
2025-11-19 17:37:43 +00:00
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;
# WebSocket support for VSCode
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# Timeout settings
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
# Buffer settings
proxy_buffering off;
proxy_request_buffering off;
}
# Proxy to code-server running on port 8443
2025-11-22 19:06:27 +00:00
# Increased rate limit for API and dynamic content
2025-11-19 17:37:43 +00:00
location / {
2025-11-22 19:06:27 +00:00
# Increased rate limiting (200 requests per minute with burst of 50)
limit_req zone=vscode_general burst=50 nodelay;
2025-11-19 17:37:43 +00:00
limit_req_status 429;
2025-11-19 19:59:53 +00:00
proxy_pass http://127.0.0.1:8443;
2025-11-19 17:37:43 +00:00
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;
# WebSocket support for VSCode
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# Timeout settings
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
# Buffer settings
proxy_buffering off;
proxy_request_buffering off;
}
# Gzip compression
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml+rss application/javascript;
# Security - deny access to hidden files
location ~ /\. {
deny all;
}
}