Skip to content

Commit 360885b

Browse files
[feat] update the nginx config
1 parent 900da40 commit 360885b

File tree

1 file changed

+46
-37
lines changed

1 file changed

+46
-37
lines changed

nginx.conf

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,66 @@
1-
worker_processes auto;
1+
worker_processes auto; # Use all available CPU cores for maximum efficiency
22

3-
# Store PID in /tmp (always writable)
4-
pid /tmp/nginx.pid;
3+
# Store PID in /tmp (this directory is always writable in containers)
4+
pid /tmp/nginx.pid; # Prevent permission issues inside Docker containers
55

66
events {
7-
worker_connections 1024;
7+
worker_connections 1024; # Max concurrent connections per worker
88
}
99

1010
http {
11-
include /etc/nginx/mime.types;
12-
default_type application/octet-stream;
13-
14-
# Disable logging to avoid permission issues
15-
access_log off;
16-
error_log /dev/stderr warn;
17-
18-
# Optimize static file serving
19-
sendfile on;
20-
tcp_nopush on;
21-
tcp_nodelay on;
22-
keepalive_timeout 65;
23-
keepalive_requests 1000;
24-
25-
# Gzip compression for optimized delivery
26-
gzip on;
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;
11+
include /etc/nginx/mime.types; # Load standard MIME types for correct content handling
12+
default_type application/octet-stream; # Fallback MIME type for unknown file types
13+
14+
# Disable access logs to avoid permission issues and reduce output noise
15+
access_log off; # Turn off access logs completely
16+
error_log /dev/stderr warn; # Send error logs to stderr for visibility in Docker
17+
18+
# Optimize static file delivery
19+
sendfile on; # Enable efficient file transfers using kernel mechanisms
20+
tcp_nopush on; # Optimize packet sizes when sending large files
21+
tcp_nodelay on; # Disable buffering for low-latency responses
22+
keepalive_timeout 65; # Time to keep connections open for reuse
23+
keepalive_requests 1000; # Allow many requests per connection before closing
24+
25+
# Enable gzip compression for faster load times
26+
gzip on; # Turn on gzip compression
27+
gzip_types # Specify which file types should be compressed
28+
text/plain
29+
text/css
30+
application/json
31+
application/javascript
32+
text/xml
33+
application/xml
34+
application/xml+rss
35+
text/javascript
36+
image/svg+xml;
37+
gzip_min_length 256; # Only compress responses larger than 256 bytes
38+
gzip_vary on; # Add Vary: Accept-Encoding header for proxies/CDNs
3039

3140
server {
32-
listen 8080;
33-
server_name localhost;
41+
listen 8080; # Expose the app on port 8080
42+
server_name localhost; # Default server name for local setups
3443

35-
# Root directory where React.js build files are placed
36-
root /usr/share/nginx/html;
37-
index index.html;
44+
# Root directory where the React build artifacts (index.html, static folder, etc.) are placed
45+
root /usr/share/nginx/html; # Serve files from this directory
46+
index index.html; # Default file served on directory access
3847

39-
# Serve React.js static files with proper caching
48+
# Main route handler — supports client-side routing in React
4049
location / {
41-
try_files $uri /index.html;
50+
try_files $uri /index.html; # If file is missing, fall back to index.html for SPA routing
4251
}
4352

44-
# Serve static assets with long cache expiration
53+
# Cache static assets aggressively for better performance
4554
location ~* \.(?:ico|css|js|gif|jpe?g|png|woff2?|eot|ttf|svg|map)$ {
46-
expires 1y;
47-
access_log off;
48-
add_header Cache-Control "public, immutable";
55+
expires 1y; # Cache for 1 year (safe for hashed filenames)
56+
access_log off; # Disable logs for static files
57+
add_header Cache-Control "public, immutable"; # Tell browsers that files won't change
4958
}
5059

51-
# Handle React.js client-side routing
60+
# Additional static assets path (React’s /static/ directory)
5261
location /static/ {
53-
expires 1y;
54-
add_header Cache-Control "public, immutable";
62+
expires 1y; # Cache assets from /static for 1 year
63+
add_header Cache-Control "public, immutable"; # Ensure long-term caching
5564
}
5665
}
5766
}

0 commit comments

Comments
 (0)