The implementation of the config needs the presence of 2 main components, which are:
Technically, everything inside Nginx Configuration is a Directive.
Directives include 2 types:
- Simple Directives
- Block Directives
Simple Directive, they are simply commands or parameters separated by spaces like listen, return and they usually end with a semicolon ;.
Block Directives are similar to Simple Directives, but instead of ending the command with a semicolon ;, they end with a pair of curly braces {}.
A Block Directive will contain many Directives inside, and we call that context. Some common types of context are:
- events {}
- Used to specify how nginx can handle requests on the server
- There is only one active events context in the Configuration File
- http {}
- Used to specify how nginx can handle requests as http or https
- There is only one http context in the Configuration File
- server {}
- Placed inside the http context
- Used to set specific information for a specific virtual server in a single server
- There can be multiple server contexts inside the http context
- Each server configuration is considered a virtual server
- main
- Contains general configuration information of Configuration Files.
- What needs to be specified outside the three headings will be written in this context.