102 lines
3.4 KiB
Text
102 lines
3.4 KiB
Text
# 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;
|
|
|
|
# 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;
|
|
|
|
proxy_pass http://localhost: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;
|
|
|
|
# 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
|
|
location / {
|
|
# Apply rate limiting
|
|
limit_req zone=vscode_general burst=10 nodelay;
|
|
limit_req_status 429;
|
|
|
|
proxy_pass http://localhost: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;
|
|
|
|
# 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;
|
|
}
|
|
}
|