nginx 1.21.1 起 mime.types 把 .js 标成 text/javascript,而 gzip_types 只写了 application/javascript,导致前端 JS 实际一直在裸传。补全类型列表, 并加上 application/json 让 API 响应也走压缩。 gzip_comp_level 此前用的是默认值 1,改为 6,实测 js+css 总量 3.85M → 3.44M。 /assets/ 下的产物文件名带内容 hash,加 immutable 永久缓存,省掉每次进页面 对 32 个 chunk 的条件请求;index.html 反过来设 no-cache,避免发版后刷不到新版。 location 里出现 add_header 会中断 http 级 add_header 的继承, 两个 block 都重新声明了原有的三个安全头。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
77 lines
2.0 KiB
Nginx Configuration File
77 lines
2.0 KiB
Nginx Configuration File
user www-data;
|
||
daemon off;
|
||
pid /tmp/nginx.pid;
|
||
worker_processes auto;
|
||
pcre_jit on;
|
||
error_log /data/log/nginx_error.log warn;
|
||
|
||
events {
|
||
worker_connections 1024;
|
||
}
|
||
|
||
http {
|
||
include /etc/nginx/mime.types;
|
||
default_type application/octet-stream;
|
||
server_tokens off;
|
||
keepalive_timeout 65;
|
||
sendfile on;
|
||
tcp_nodelay on;
|
||
|
||
gzip on;
|
||
gzip_vary on;
|
||
gzip_comp_level 6;
|
||
gzip_min_length 1024;
|
||
# nginx 1.21.1 起 mime.types 把 .js 标成 text/javascript,
|
||
# 只写 application/javascript 会导致前端 JS 完全不压缩,两个都要留。
|
||
# text/html 是内置的,不用也不能写在这里。
|
||
gzip_types
|
||
text/javascript
|
||
application/javascript
|
||
text/css
|
||
application/json
|
||
image/svg+xml
|
||
text/plain;
|
||
|
||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||
'$status $body_bytes_sent "$http_referer" '
|
||
'"$http_user_agent" "$http_x_forwarded_for"';
|
||
|
||
map $request $loggable {
|
||
default 1;
|
||
"~*^POST /api/judge_server_heartbeat/ HTTP/1\.1$" 0;
|
||
}
|
||
|
||
access_log /data/log/nginx_access.log main if=$loggable;
|
||
# access_log off;
|
||
|
||
upstream backend {
|
||
server 127.0.0.1:8080;
|
||
keepalive 32;
|
||
}
|
||
|
||
add_header X-XSS-Protection "1; mode=block" always;
|
||
add_header X-Frame-Options SAMEORIGIN always;
|
||
add_header X-Content-Type-Options nosniff always;
|
||
|
||
server {
|
||
listen 8000 default_server;
|
||
server_name _;
|
||
|
||
include locations.conf;
|
||
}
|
||
|
||
# server {
|
||
# listen 1443 ssl http2 default_server;
|
||
# server_name _;
|
||
# ssl_certificate /data/ssl/server.crt;
|
||
# ssl_certificate_key /data/ssl/server.key;
|
||
# ssl_protocols TLSv1.2;
|
||
# ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
|
||
# ssl_prefer_server_ciphers on;
|
||
# ssl_session_cache shared:SSL:10m;
|
||
|
||
# include https_locations.conf;
|
||
# }
|
||
|
||
}
|