include

The 'include' directive allows configuration files to be included within NGINX configuration files, facilitating modular configurations.

Syntaxinclude path;
Defaultnone
Context
Arguments1

Description

The 'include' directive is designed to enhance modularity and maintainability of NGINX configuration by allowing the inclusion of other configuration files. This helps break down large configuration files into manageable pieces, allowing for easier updates and organization. By using the 'include' directive, users can define common settings in a separate file and include them wherever needed across different configuration contexts, promoting DRY (Don't Repeat Yourself) principles.

The argument for the 'include' directive consists of the path to one or multiple configuration files. The path can be specified as an absolute path or as a relative path from the current working directory. Wildcards are also supported, enabling the inclusion of multiple files that match a specified pattern. When NGINX processes the main configuration file, it resolves and reads the files specified in the 'include' directive in the order they appear. The directives within these files are then merged into the current context, allowing them to influence the configuration settings accordingly.

Configuration files included with this directive can define various aspects of NGINX, such as location blocks, server settings, or upstream configurations. However, care should be taken to avoid conflicts with existing settings in the primary configuration file. If the included file contains directives that alter already defined configurations, the last defined value in the merged configuration will take precedence. This flexibility makes the 'include' directive a powerful tool for structuring complex NGINX configurations effectively.

Config Example

# Example of using the 'include' directive
include /etc/nginx/conf.d/*.conf;

Ensure that included files do not contain conflicting directives that may cause ambiguity in configuration.

Relative paths for included files may lead to unexpected behavior if the current working directory changes.

Using wildcards can include unintended files if not specified carefully.

← Back to all directives