Skip to content

Commit e9ed7df

Browse files
[fix] nginx config
1 parent 24d4b2c commit e9ed7df

1 file changed

Lines changed: 30 additions & 29 deletions

File tree

nginx.conf

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,57 @@
11
worker_processes auto;
2-
error_log /var/log/nginx/error.log warn;
2+
3+
# Store PID in /tmp (always writable)
34
pid /tmp/nginx.pid;
45

56
events {
67
worker_connections 1024;
78
}
89

910
http {
10-
include /etc/nginx/mime.types;
11-
default_type application/octet-stream;
11+
include /etc/nginx/mime.types;
12+
default_type application/octet-stream;
1213

13-
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
14-
'$status $body_bytes_sent "$http_referer" '
15-
'"$http_user_agent" "$http_x_forwarded_for"';
14+
# Disable logging to avoid permission issues
15+
access_log off;
16+
error_log /dev/stderr warn;
1617

17-
access_log /var/log/nginx/access.log main;
18+
# Optimize static file serving
19+
sendfile on;
20+
tcp_nopush on;
21+
tcp_nodelay on;
22+
keepalive_timeout 65;
23+
keepalive_requests 1000;
1824

19-
sendfile on;
20-
tcp_nopush on;
21-
keepalive_timeout 65;
25+
# Gzip compression for optimized delivery
2226
gzip on;
23-
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
27+
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml;
28+
gzip_min_length 256;
29+
gzip_vary on;
2430

2531
server {
26-
listen 8080;
27-
server_name localhost;
32+
listen 8080;
33+
server_name localhost;
34+
35+
# Root directory where React.js build files are placed
2836
root /usr/share/nginx/html;
2937
index index.html;
3038

31-
# Security headers
32-
add_header X-Frame-Options "SAMEORIGIN" always;
33-
add_header X-Content-Type-Options "nosniff" always;
34-
add_header X-XSS-Protection "1; mode=block" always;
35-
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
36-
37-
# SPA routing - serve index.html for all routes
39+
# Serve React.js static files with proper caching
3840
location / {
39-
try_files $uri $uri/ /index.html;
41+
try_files $uri /index.html;
4042
}
4143

42-
# Cache static assets
43-
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
44+
# Serve static assets with long cache expiration
45+
location ~* \.(?:ico|css|js|gif|jpe?g|png|woff2?|eot|ttf|svg|map)$ {
4446
expires 1y;
47+
access_log off;
4548
add_header Cache-Control "public, immutable";
4649
}
4750

48-
# Health check endpoint
49-
location /health {
50-
access_log off;
51-
return 200 "healthy\n";
52-
add_header Content-Type text/plain;
51+
# Handle React.js client-side routing
52+
location /static/ {
53+
expires 1y;
54+
add_header Cache-Control "public, immutable";
5355
}
5456
}
5557
}
56-

0 commit comments

Comments
 (0)