|
42 | 42 | # sudo certbot renew --force-renewal |
43 | 43 | # sudo systemctl reload nginx |
44 | 44 |
|
45 | | -events { |
46 | | - worker_connections 1024; |
| 45 | +# Redirect HTTP to HTTPS |
| 46 | +server { |
| 47 | + listen 80; |
| 48 | + server_name realworld.minhhoccode111.com; |
| 49 | + return 301 https://$server_name$request_uri; |
47 | 50 | } |
48 | 51 |
|
49 | | -http { |
50 | | - include /etc/nginx/mime.types; |
51 | | - default_type application/octet-stream; |
| 52 | +# Frontend static serving |
| 53 | +server { |
| 54 | + listen 443 ssl http2; |
| 55 | + server_name realworld.minhhoccode111.com; |
52 | 56 |
|
53 | | - sendfile on; |
54 | | - sendfile_max_chunk 1m; |
55 | | - tcp_nopush on; |
56 | | - tcp_nodelay on; |
57 | | - keepalive_timeout 65; |
| 57 | + # TLS certificates |
| 58 | + ssl_certificate /etc/letsencrypt/live/realworld.minhhoccode111.com/fullchain.pem; |
| 59 | + ssl_certificate_key /etc/letsencrypt/live/realworld.minhhoccode111.com/privkey.pem; |
58 | 60 |
|
59 | | - open_file_cache max=1000 inactive=20s; |
60 | | - open_file_cache_valid 30; |
61 | | - open_file_cache_min_uses 2; |
| 61 | + # Path to your React 'dist' or 'build' folder |
| 62 | + root /var/www/realworld-react/dist; |
| 63 | + index index.html; |
62 | 64 |
|
63 | | - # Logging |
64 | | - # access_log /var/log/nginx/access.log main; |
65 | | - error_log /var/log/nginx/error.log; |
66 | | - |
67 | | - # Rate Limit |
68 | | - limit_req_zone $binary_remote_addr zone=static_limit:10m rate=30r/s; |
69 | | - limit_req_status 429; |
70 | | - |
71 | | - # Compression |
72 | | - gzip on; |
73 | | - gzip_vary on; |
74 | | - gzip_proxied any; |
75 | | - gzip_comp_level 6; |
76 | | - gzip_types |
77 | | - text/plain |
78 | | - text/css |
79 | | - application/json |
80 | | - application/javascript |
81 | | - text/xml |
82 | | - application/xml |
83 | | - image/svg+xml; |
84 | | - |
85 | | - # Redirect HTTP to HTTPS |
86 | | - server { |
87 | | - listen 80; |
88 | | - server_name realworld.minhhoccode111.com; |
89 | | - return 301 https://$server_name$request_uri; |
| 65 | + # React Router Fix: Fallback to index.html for SPA routing |
| 66 | + location / { |
| 67 | + try_files $uri $uri/ /index.html; |
90 | 68 | } |
91 | 69 |
|
92 | | - # Frontend static serving |
93 | | - server { |
94 | | - listen 443 ssl http2; |
95 | | - server_name realworld.minhhoccode111.com; |
96 | | - |
97 | | - # TLS certificates |
98 | | - ssl_certificate /etc/letsencrypt/live/realworld.minhhoccode111.com/fullchain.pem; |
99 | | - ssl_certificate_key /etc/letsencrypt/live/realworld.minhhoccode111.com/privkey.pem; |
100 | | - |
101 | | - # Strong TLS settings |
102 | | - ssl_protocols TLSv1.2 TLSv1.3; |
103 | | - ssl_prefer_server_ciphers off; |
104 | | - ssl_session_cache shared:SSL:10m; |
105 | | - ssl_session_timeout 1d; |
| 70 | + # Static Assets Caching |
| 71 | + location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ { |
| 72 | + # limit_req zone=static_limit burst=20 nodelay; |
106 | 73 |
|
107 | | - # Path to your React 'dist' or 'build' folder |
108 | | - root /var/www/realworld-react/dist; |
109 | | - index index.html; |
110 | | - |
111 | | - # React Router Fix: Fallback to index.html for SPA routing |
112 | | - location / { |
113 | | - try_files $uri $uri/ /index.html; |
114 | | - } |
115 | | - |
116 | | - # Static Assets Caching |
117 | | - location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ { |
118 | | - limit_req zone=static_limit burst=20 nodelay; |
119 | | - |
120 | | - etag on; |
121 | | - expires 1y; |
122 | | - add_header Cache-Control "public, immutable"; |
123 | | - access_log off; |
124 | | - } |
| 74 | + etag on; |
| 75 | + expires 1y; |
| 76 | + add_header Cache-Control "public, immutable"; |
| 77 | + access_log off; |
| 78 | + } |
125 | 79 |
|
126 | | - # Security Headers |
127 | | - add_header X-Frame-Options "SAMEORIGIN"; |
128 | | - add_header X-Content-Type-Options "nosniff"; |
129 | | - add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; |
130 | | - add_header X-XSS-Protection "1; mode=block"; |
131 | | - add_header Referrer-Policy "strict-origin-when-cross-origin"; |
132 | | - add_header Permissions-Policy "geolocation=(), camera=(), microphone=()" always; |
| 80 | + # Security Headers |
| 81 | + add_header Permissions-Policy "geolocation=(),midi=(),sync-xhr=(),microphone=(),camera=(),magnetometer=(),gyroscope=(),fullscreen=(self),payment=()"; |
133 | 82 |
|
134 | | - # Health check |
135 | | - location /health { |
136 | | - access_log off; |
137 | | - return 200 "healthy\n"; |
138 | | - add_header Content-Type text/plain; |
139 | | - } |
| 83 | + # Health check |
| 84 | + location /health { |
| 85 | + access_log off; |
| 86 | + return 200 "healthy\n"; |
| 87 | + add_header Content-Type text/plain; |
140 | 88 | } |
141 | 89 | } |
0 commit comments