核心逻辑是利用 ln -s(软链接)来控制配置文件的“生效”与“失效”。
/etc/nginx/sites-available/= 仓库(库存)- 这里存放你写好的所有配置文件。
- 特点:放在这里的文件不会生效,Nginx 不会去读取它。
- 作用:存档、备份、草稿、暂时下线的网站。
/etc/nginx/sites-enabled/= 货架(展示位)- 这里只存放指向
sites-available的软链接。 - 特点:Nginx 的主配置文件 (
nginx.conf) 只会include这个目录下的文件。 - 作用:决定当前哪些网站是“活着”的。
- 这里只存放指向
nginx.conf 基础配置信息:
text
user root;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 1024;
}
http {
# ===== 基础设置 =====
sendfile on;
tcp_nopush on;
types_hash_max_size 2048;
server_tokens off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# ===== 日志设置 =====
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
# ===== Gzip 压缩 =====
gzip on;
gzip_types text/plain text/css application/javascript application/json application/xml application/rss+xml image/svg+xml;
# ===== Keep-Alive 设置 =====
keepalive_timeout 300s;
keepalive_requests 1000;
# ===== SSL 全局优化 (所有站点共用) =====
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers off;
ssl_session_cache shared:SSL:50m;
ssl_session_timeout 1h;
ssl_session_tickets on;
# ===== 关键:引入其他配置文件 =====
# 这里会加载 sites-enabled 目录下的所有文件
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
然后在 /etc/nginx/sites-available 编写对应的信息 一个 server 模块可以直接一个模块内容,这样也非常好迁移。 以探针为例:vim komari
text
server {
listen 443 ssl http2;
server_name net.jacin.me;
ssl_certificate /root/fast-proxy/ssl/origin.crt;
ssl_certificate_key /root/fast-proxy/ssl/origin.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers off;
location / {
proxy_pass http://localhost:25774;
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_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
# 禁用代理缓冲
proxy_buffering off;
# 允许大文件上传(50M)
client_max_body_size 50M;
}
}
写完后,可以在 nginx.conf 同目录下: vim up.sh
text
ln -sf /etc/nginx/sites-available/* /etc/nginx/sites-enabled/
nginx -t && systemctl reload nginx
直接就分模块完成了。
评论
还没有评论,来发第一个吧