-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnginx.conf
113 lines (95 loc) · 3.14 KB
/
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# User and worker settings
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
# MIME types and default settings
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Logging settings
access_log /var/log/nginx/access.log combined;
# Gzip Compression
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types
text/plain
text/css
application/json
application/javascript
application/x-javascript
text/xml
application/xml
application/xml+rss
image/svg+xml;
# Caching Settings
open_file_cache max=1000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
# Security Headers
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header Referrer-Policy "no-referrer-when-downgrade";
add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline';";
# SSL Settings (Optional: Uncomment if using SSL)
# listen 443 ssl http2;
# ssl_certificate /etc/ssl/certs/your_certificate.crt;
# ssl_certificate_key /etc/ssl/private/your_private.key;
# include /etc/nginx/ssl-params.conf;
# HTTP Server
server {
listen 80;
server_name yourdomain.com; # Replace with your domain
root /usr/share/nginx/html;
index index.html index.htm;
# Serve static files with caching
location /static/ {
expires 30d;
add_header Cache-Control "public, max-age=2592000, immutable";
}
# Handle API requests (if applicable)
# location /api/ {
# proxy_pass http://backend:5000; # Replace with your backend service
# proxy_http_version 1.1;
# proxy_set_header Upgrade $http_upgrade;
# proxy_set_header Connection 'upgrade';
# proxy_set_header Host $host;
# proxy_cache_bypass $http_upgrade;
# }
# Handle React Router (client-side routing)
location / {
try_files $uri $uri/ /index.html;
}
# Enable compression for responses
gzip on;
# Optional: Enable Brotli compression if installed
# brotli on;
# brotli_comp_level 6;
# brotli_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss image/svg+xml;
# Error Pages
error_page 404 /404.html;
location = /404.html {
internal;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
internal;
}
}
# Redirect HTTP to HTTPS (Optional: Uncomment if using SSL)
# server {
# listen 80;
# server_name yourdomain.com;
# return 301 https://$host$request_uri;
# }
}