大网数据广告活动
服务器运维问答

nginx split large configuration file

· 52CE 我爱测

My nginx default configuration file is becoming huge. I'd like to split it to smaller config files, each including only one, maximum 4 locations to each file, so that I can enable/disable them quickly. Actual file looks like this…

问题原文

原帖链接 · oliverjkb · CC BY-SA 3.0

My nginx default configuration file is becoming huge. I'd like to split it to smaller config files, each including only one, maximum 4 locations to each file, so that I can enable/disable them quickly.

Actual file looks like this:

server {
    listen 80 default_server;
    root /var/www/

    location /1 {
        config info...;
    }

    location /2 {
        config info....;
    }        
    location /abc {
        proxy_pass...;
    }

    location /xyz {
        fastcgi_pass....;
    }
    location /5678ab {
        config info...;
    }

    location /admin {
        config info....;
    }

now, if I want to split that up to have only a few locations in each file (locations belonging together), what would be a proper way to do it without causing chaos (like declaring root in each file, hence having weird path's that nginx tries to find files) ?

已采纳解答

原帖链接 · FLXN · CC BY-SA 4.0

You are probably looking for Nginx's include function: http://nginx.org/en/docs/ngx_core_module.html#include

You can use it like this:

server {
  listen 80;
  server_name example.com;
  […]
  include conf/location.conf;
}

include also accepts wildcards so you could also write

include include/*.conf;

to include every *.conf file in the directory include.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2015-07-23)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。