Javatpoint Logo
Javatpoint Logo

NGINX Directives

Nginx consists of modules that are controlled by directives defined in the configuration file. Directives are divided into two parts:

  • Simple Directive: A simple directive consists of the name and parameters separated by spaces and ends with a semicolon (;).
  • Block Directive: The structure of block directive is similar to the simple directive, but instead of semicolon, it ends with a set of additional instructions surrounded by curly braces ({ and }). If a block directive can have other directives inside the braces, then it is known as context. Eg. Events, http, location, and server.

Directives placed in the configuration file outside of any contexts are considered to be in the main context. The events and http directives reside in the main context, server resides in http and location in the server.

Let's see the list of some important directives:

Directive Syntax Default Context
absolute_redirect absolute_redirect on | off; absolute_redirect on; http, server, location
accept_mutex accept_mutex on | off; off Events
accept_mutex_delay accept_mutex_delay time; accept_mutex_delay 500ms; Events
access_log (ngx_http_log_module) access_log path [format [buffer=size] [gzip[=level]] [flush=time] [if=condition]];
access_log off;
access_log logs/access.log combined; http, server, location, if in location, limit_except
access_log (ngx_stream_log_module) access_log path format [buffer=size] [gzip[=level]] [flush=time] [if=condition];
access_log off;
access_log off; stream, server
add_after_body add_before_body uri; - http, server, location
add_before_body add_before_body uri; - http, server, location
add_header add_header name value [always]; - http, server, location, if in location
add_trailer add_trailer name value [always]; - http, server, location, if in location
addition_types addition_types mime-type ...; addition_types text/html; http, server, location
aio aio on | off | threads[=pool]; aio off; http, server, location
aio_write aio_write on | off; aio_write off; http, server, location
alias alias path; - Location
allow (ngx_http_access_module) allow address | CIDR | unix: | all; - http, server, location, limit_except
allow (ngx_stream_access_module) allow address | CIDR | unix: | all; - Stream, server
ancient_browser ancient_browser string ...; - http, server, location
ancient_browser_value ancient_browser_value string; ancient_browser_value 1; http, server, location
api api [write=on|off]; - location
auth_basic auth_basic string | off; auth_basic off; http, server, location, limit_except
auth_basic_user_file auth_basic_user_file file; - http, server, location, limit_except
auth_http auth_http URL; - mail, server
auth_http_header auth_http_header header value; - mail, server
auth_http_pass_client_cert auth_http_pass_client_cert on | off; auth_http_pass_client_cert off; mail, server
auth_http_timeout auth_http_timeout time auth_http_timeout 60s; mail, server
auth_jwt auth_jwt string [token=$variable] | off; auth_jwt off; http, server, location, limit_except
auth_jwt_claim_set auth_jwt_claim_set $variable name ...; - http
auth_jwt_header_set auth_jwt_header_set $variable name ...; - http
auth_jwt_key_file auth_jwt_key_file file; - ttp, server, location, limit_except

Next TopicNGINX Variables

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA