共计 1276 个字符,预计需要花费 4 分钟才能阅读完成。
Nginx 中的 include 语法能够用于提取反复的配置项,精简 nginx.conf 单文件。
include 语法能够用在 nginx.conf 文件的任何中央,前提是 include 引入的文件本身语法正确。
include 引入的文件门路能够是绝对路径,也能够是相对路径。相对路径以 nginx.conf 为基准。
include 能够应用通配符。
# 绝对路径
include /etc/conf/status.conf
# 相对路径
include status.conf
# 通配符
include /etc/conf/baseConf/*.conf
include *.conf
具体应用
原配置如下:
conf/nginx.conf
// ↓ nginx.conf
# ... 省略其余...
http {
# ===↓proxy↓===
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 50M;
client_body_buffer_size 256k;
proxy_connect_timeout 600;
proxy_send_timeout 300;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
# ===↑proxy↑===
# ===↓status↓===
location /status {
stub_status on;
access_log off;
allow all;
}
# ===↑status↑===
}
# ... 省略其余...
应用 includes 革新后如下:
conf/nginx.conf
conf/proxy.conf
conf/status.conf
// ↓ nginx.conf
# ... 省略其余...
http {
include proxy.conf;
include status.conf;
}
# ... 省略其余...
// ↓conf/proxy.conf
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 50M;
client_body_buffer_size 256k;
proxy_connect_timeout 600;
proxy_send_timeout 300;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
// ↓conf/status.conf
location /status {
stub_status on;
access_log off;
allow all;
}
完结。
同步更新到本人的语雀
https://www.yuque.com/diracke…
正文完