Nginx

Nginx Config

  • Main context: Which is outside of all contexts and is not under any {}. Many of the directives defined in main/global context are not inheritable to other or child contexts as they are final and affect the entire application.
  • Otherwise in general, directives are inheritable i.e. if it is defined at the upper level, it will carry the same value in child context as default. You can always override the value. The arrays are over-written and not appended.
  • The “events” context is contained within the “main” context. It is used to set global options that affect how Nginx handles connections at a general level. There can only be a single events context defined within the Nginx configuration.
  • Nginx uses an event-based connection processing model, so the directives defined within EVENT context determine how worker processes should handle connections.
  • HTTP Context: When configuring Nginx as a web server or reverse proxy, the “http” context will hold the majority of the configuration. This context will contain all of the directives and other contexts necessary to define how the program will handle HTTP or HTTPS connections. The http context is a sibling of the events context, so they should be listed side-by-side, rather than nested. They both are children of the main context.
  • The “server” context is declared within the “http” context.
  • Location Context: Defined within the server context. They can be nested inside one another.
  • The upstream context is used to define and configure “upstream” servers. Basically, this context defines a named pool of servers that Nginx can then proxy requests to. This context will likely be used when you are configuring proxies of various types. The upstream context should be placed within the http context, outside of any specific server contexts.

References: https://www.nginx.com/resources/wiki/start/topics/examples/full/

https://www.digitalocean.com/community/tutorials/understanding-the-nginx-configuration-file-structure-and-configuration-contexts

Directives in details:

  • http://nginx.org/en/docs/ngx_core_module.html
  • http://nginx.org/en/docs/http/ngx_http_core_module.html

OpenResty Config

https://openresty-reference.readthedocs.io/en/latest/Directives/

Written on December 14, 2018