|
| 1 | +# ProStaff API - Nginx Server Configuration |
| 2 | + |
| 3 | +# HTTP - Redirect to HTTPS |
| 4 | +server { |
| 5 | + listen 80; |
| 6 | + listen [::]:80; |
| 7 | + server_name api.prostaff.gg staging-api.prostaff.gg; |
| 8 | + |
| 9 | + # Health check endpoint (HTTP OK) |
| 10 | + location /health { |
| 11 | + access_log off; |
| 12 | + return 200 "healthy\n"; |
| 13 | + add_header Content-Type text/plain; |
| 14 | + } |
| 15 | + |
| 16 | + # Redirect all other traffic to HTTPS |
| 17 | + location / { |
| 18 | + return 301 https://$server_name$request_uri; |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +# HTTPS - Production |
| 23 | +server { |
| 24 | + listen 443 ssl http2; |
| 25 | + listen [::]:443 ssl http2; |
| 26 | + server_name api.prostaff.gg; |
| 27 | + |
| 28 | + # SSL Configuration |
| 29 | + ssl_certificate /etc/nginx/ssl/fullchain.pem; |
| 30 | + ssl_certificate_key /etc/nginx/ssl/privkey.pem; |
| 31 | + ssl_protocols TLSv1.2 TLSv1.3; |
| 32 | + ssl_ciphers HIGH:!aNULL:!MD5; |
| 33 | + ssl_prefer_server_ciphers on; |
| 34 | + ssl_session_cache shared:SSL:10m; |
| 35 | + ssl_session_timeout 10m; |
| 36 | + |
| 37 | + # HSTS |
| 38 | + add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; |
| 39 | + |
| 40 | + # Logs |
| 41 | + access_log /var/log/nginx/prostaff-access.log main; |
| 42 | + error_log /var/log/nginx/prostaff-error.log warn; |
| 43 | + |
| 44 | + # Root directory |
| 45 | + root /app/public; |
| 46 | + |
| 47 | + # Rate limiting |
| 48 | + limit_req zone=api burst=50 nodelay; |
| 49 | + |
| 50 | + # Serve static files directly |
| 51 | + location ~ ^/(assets|packs|images|javascripts|stylesheets|system)/ { |
| 52 | + gzip_static on; |
| 53 | + expires max; |
| 54 | + add_header Cache-Control public; |
| 55 | + access_log off; |
| 56 | + try_files $uri @app; |
| 57 | + } |
| 58 | + |
| 59 | + # Health check |
| 60 | + location /up { |
| 61 | + proxy_pass http://prostaff_api; |
| 62 | + proxy_set_header Host $host; |
| 63 | + access_log off; |
| 64 | + } |
| 65 | + |
| 66 | + # API Documentation (Swagger) |
| 67 | + location /api-docs { |
| 68 | + proxy_pass http://prostaff_api; |
| 69 | + proxy_set_header Host $host; |
| 70 | + proxy_set_header X-Real-IP $remote_addr; |
| 71 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 72 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 73 | + } |
| 74 | + |
| 75 | + # Proxy to Rails app |
| 76 | + location / { |
| 77 | + proxy_pass http://prostaff_api; |
| 78 | + proxy_set_header Host $host; |
| 79 | + proxy_set_header X-Real-IP $remote_addr; |
| 80 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 81 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 82 | + proxy_set_header X-Forwarded-Port $server_port; |
| 83 | + |
| 84 | + # Timeouts |
| 85 | + proxy_connect_timeout 60s; |
| 86 | + proxy_send_timeout 60s; |
| 87 | + proxy_read_timeout 60s; |
| 88 | + |
| 89 | + # Buffering |
| 90 | + proxy_buffering on; |
| 91 | + proxy_buffer_size 4k; |
| 92 | + proxy_buffers 8 4k; |
| 93 | + |
| 94 | + # WebSocket support |
| 95 | + proxy_http_version 1.1; |
| 96 | + proxy_set_header Upgrade $http_upgrade; |
| 97 | + proxy_set_header Connection "upgrade"; |
| 98 | + } |
| 99 | + |
| 100 | + # Error pages |
| 101 | + error_page 500 502 503 504 /500.html; |
| 102 | + location = /500.html { |
| 103 | + root /app/public; |
| 104 | + internal; |
| 105 | + } |
| 106 | +} |
| 107 | + |
| 108 | +# HTTPS - Staging |
| 109 | +server { |
| 110 | + listen 443 ssl http2; |
| 111 | + listen [::]:443 ssl http2; |
| 112 | + server_name staging-api.prostaff.gg; |
| 113 | + |
| 114 | + # SSL Configuration (same as production) |
| 115 | + ssl_certificate /etc/nginx/ssl/staging-fullchain.pem; |
| 116 | + ssl_certificate_key /etc/nginx/ssl/staging-privkey.pem; |
| 117 | + ssl_protocols TLSv1.2 TLSv1.3; |
| 118 | + ssl_ciphers HIGH:!aNULL:!MD5; |
| 119 | + ssl_prefer_server_ciphers on; |
| 120 | + |
| 121 | + # Rest of config same as production |
| 122 | + root /app/public; |
| 123 | + access_log /var/log/nginx/staging-access.log main; |
| 124 | + error_log /var/log/nginx/staging-error.log warn; |
| 125 | + |
| 126 | + location / { |
| 127 | + proxy_pass http://prostaff_api; |
| 128 | + proxy_set_header Host $host; |
| 129 | + proxy_set_header X-Real-IP $remote_addr; |
| 130 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 131 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 132 | + } |
| 133 | +} |
0 commit comments