72 lines
1.9 KiB
Nginx Configuration File
72 lines
1.9 KiB
Nginx Configuration File
events {
|
||
worker_connections 1024;
|
||
}
|
||
|
||
http {
|
||
# --- 基础 IO 优化 ---
|
||
sendfile on;
|
||
tcp_nopush on;
|
||
tcp_nodelay on;
|
||
|
||
# --- Keepalive ---
|
||
keepalive_timeout 65;
|
||
keepalive_requests 1000;
|
||
|
||
# --- 客户端超时(防慢连接拖死 worker)---
|
||
client_max_body_size 16m;
|
||
client_body_buffer_size 128k;
|
||
client_header_buffer_size 1k;
|
||
large_client_header_buffers 4 8k;
|
||
client_body_timeout 30s;
|
||
client_header_timeout 30s;
|
||
send_timeout 30s;
|
||
|
||
# --- 反代默认参数(各 conf.d 可按需覆盖)---
|
||
proxy_http_version 1.1;
|
||
proxy_set_header Host $host;
|
||
proxy_set_header X-Real-IP $remote_addr;
|
||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||
proxy_set_header X-Forwarded-Proto $scheme;
|
||
proxy_set_header Connection "";
|
||
proxy_connect_timeout 3s;
|
||
proxy_send_timeout 30s;
|
||
proxy_read_timeout 30s;
|
||
proxy_buffer_size 16k;
|
||
proxy_buffers 8 16k;
|
||
proxy_busy_buffers_size 32k;
|
||
|
||
# --- Gzip 压缩 ---
|
||
gzip on;
|
||
gzip_min_length 1k;
|
||
gzip_comp_level 5;
|
||
gzip_types text/plain text/css application/json application/javascript application/xml image/svg+xml;
|
||
gzip_proxied any;
|
||
gzip_vary on;
|
||
|
||
# --- SSL 会话缓存 ---
|
||
ssl_session_cache shared:SSL:10m;
|
||
ssl_session_timeout 1d;
|
||
ssl_session_tickets on;
|
||
|
||
# --- 关闭版本号 ---
|
||
server_tokens off;
|
||
|
||
include /etc/nginx/conf.d/*.conf;
|
||
|
||
# 所有 HTTP 自动跳 HTTPS
|
||
server {
|
||
listen 80 default_server;
|
||
server_name _;
|
||
|
||
location / {
|
||
return 301 https://$host$request_uri;
|
||
}
|
||
|
||
# 让证书续期正常工作(必须留)
|
||
location /.well-known/acme-challenge/ {
|
||
root /var/www/html;
|
||
try_files $uri =404;
|
||
}
|
||
}
|
||
}
|