Spaces:
Running
Running
Chandima Prabhath
commited on
Commit
·
29f13f9
1
Parent(s):
cc2caf9
Refactor Nginx configuration for improved performance and security
Browse files- nginx.conf +86 -22
nginx.conf
CHANGED
@@ -1,31 +1,95 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
events {
|
|
|
|
|
|
|
4 |
|
5 |
http {
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
keepalive_timeout 65;
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
14 |
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
17 |
|
18 |
-
#
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
expires 30d;
|
26 |
-
add_header Cache-Control "public";
|
27 |
}
|
28 |
-
}
|
29 |
}
|
30 |
-
|
31 |
-
|
|
|
1 |
+
#------------------------------------------------------------------
|
2 |
+
# Global Settings
|
3 |
+
#------------------------------------------------------------------
|
4 |
+
worker_processes auto;
|
5 |
+
worker_rlimit_nofile 100000;
|
6 |
|
7 |
+
events {
|
8 |
+
worker_connections 4096;
|
9 |
+
multi_accept on;
|
10 |
+
}
|
11 |
|
12 |
http {
|
13 |
+
# Basic includes
|
14 |
+
include /opt/bitnami/nginx/conf/mime.types;
|
15 |
+
default_type application/octet-stream;
|
|
|
16 |
|
17 |
+
# I/O optimizations
|
18 |
+
sendfile on;
|
19 |
+
tcp_nopush on;
|
20 |
+
tcp_nodelay on;
|
21 |
+
keepalive_timeout 65;
|
22 |
|
23 |
+
# Caching open file descriptors
|
24 |
+
open_file_cache max=1000 inactive=20s;
|
25 |
+
open_file_cache_valid 30s;
|
26 |
+
open_file_cache_min_uses 2;
|
27 |
+
open_file_cache_errors off;
|
28 |
|
29 |
+
# Hide Nginx version
|
30 |
+
server_tokens off;
|
31 |
+
|
32 |
+
#------------------------------------------------------------------
|
33 |
+
# Gzip Compression
|
34 |
+
#------------------------------------------------------------------
|
35 |
+
gzip on;
|
36 |
+
gzip_disable "msie6";
|
37 |
+
gzip_vary on;
|
38 |
+
gzip_proxied any;
|
39 |
+
gzip_comp_level 5;
|
40 |
+
gzip_buffers 16 8k;
|
41 |
+
gzip_http_version 1.1;
|
42 |
+
gzip_types
|
43 |
+
text/plain
|
44 |
+
text/css
|
45 |
+
application/json
|
46 |
+
application/javascript
|
47 |
+
text/xml
|
48 |
+
application/xml
|
49 |
+
application/xml+rss
|
50 |
+
text/javascript;
|
51 |
+
|
52 |
+
# (If your image supports Brotli, you could also enable it here)
|
53 |
+
|
54 |
+
#------------------------------------------------------------------
|
55 |
+
# Server Block
|
56 |
+
#------------------------------------------------------------------
|
57 |
+
server {
|
58 |
+
listen 7860;
|
59 |
+
listen [::]:7860;
|
60 |
+
server_name localhost;
|
61 |
+
|
62 |
+
root /usr/share/nginx/html;
|
63 |
+
index index.html;
|
64 |
+
|
65 |
+
# Security headers
|
66 |
+
add_header X-Frame-Options "SAMEORIGIN";
|
67 |
+
add_header X-Content-Type-Options "nosniff";
|
68 |
+
add_header X-XSS-Protection "1; mode=block";
|
69 |
+
add_header Referrer-Policy "no-referrer-when-downgrade";
|
70 |
+
# add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
|
71 |
+
|
72 |
+
# SPA routing: try file, dir, then fallback to index.html
|
73 |
+
location / {
|
74 |
+
try_files $uri $uri/ /index.html;
|
75 |
+
}
|
76 |
+
|
77 |
+
# Static assets: long cache + no logs
|
78 |
+
location ~* \.(?:css|js|json|txt|xml|woff2?|ttf|eot)$ {
|
79 |
+
access_log off;
|
80 |
+
log_not_found off;
|
81 |
+
expires 30d;
|
82 |
+
add_header Cache-Control "public, no-transform";
|
83 |
+
}
|
84 |
+
|
85 |
+
location ~* \.(?:png|jpe?g|gif|ico|svg)$ {
|
86 |
+
access_log off;
|
87 |
+
log_not_found off;
|
88 |
+
expires 30d;
|
89 |
+
add_header Cache-Control "public, no-transform";
|
90 |
+
}
|
91 |
|
92 |
+
# Fallback 404s to index for client‑side routing
|
93 |
+
error_page 404 /index.html;
|
|
|
|
|
94 |
}
|
|
|
95 |
}
|
|
|
|