gpt4 book ai didi

nginx - nginx 如何选择配置顺序?

转载 作者:行者123 更新时间:2023-12-04 13:43:35 30 4
gpt4 key购买 nike

在我的/etc/nginx/nginx.conf 文件中,我有配置。作为:-

user  nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf;
}

现在,我不喜欢污染默认的 nginx.conf 文件,所以我将/etc/nginx/conf.d/default.conf 中的配置保留为:-
worker_processes 2;
events {
worker_connections 2048;
}

我的问题是,在上述情况下,nginx 会覆盖或从 default.conf 文件或 nginx.conf 文件中选择 worker_processes 和 worker_connections 的配置吗?另外,我想知道 nginx 是如何处理配置文件的?

最佳答案

对于“nginx 如何处理配置文件”,一种简单的查看方式是:

  • 读取配置开始于 /etc/nginx/nginx.conf
  • 指令从上到下读取
  • include将文件插入到 include 的位置
    类似于 C 预处理器的方式
  • 设置具有范围,例如 http , server , 或 location ,按从宽到窄的顺序
  • 某些设置可以发生在多个范围级别
  • 在较窄范围内设置参数会覆盖在较宽范围内相同参数的设置
  • 同一范围内的冲突设置被拒绝

  • 有关详细信息,请参阅有关 Nginx 目录结构的 Debian wiki 文章。

    关于nginx - nginx 如何选择配置顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38370884/

    30 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com