NGINX 指令

2024 年 8 月 29 日 | 阅读 2 分钟

Nginx 由模块组成,这些模块由配置文件中定义的指令控制。 指令分为两部分

  • 简单指令: 简单指令由名称和用空格分隔的参数组成,并以分号 (;) 结尾。
  • 块指令: 块指令的结构类似于简单指令,但它不是以分号结尾,而是以一组由大括号 ({ 和 }) 括起来的附加指令结尾。 如果块指令可以在大括号内包含其他指令,则称其为上下文。 例如。 Events, http, location 和 server。

放置在任何上下文之外的配置文件中的指令被认为位于 main 上下文 中。 eventshttp 指令位于 main 上下文,server 位于 http 上下文,location 位于 server 上下文。

让我们看看一些重要的指令的列表

指令语法默认背景
absolute_redirectabsolute_redirect on | off;absolute_redirect on;http, server, location
accept_mutexaccept_mutex on | off;off事件
accept_mutex_delayaccept_mutex_delay time;accept_mutex_delay 500ms;事件
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_bodyadd_before_body uri;-http, server, location
add_before_bodyadd_before_body uri;-http, server, location
add_headeradd_header name value [always];-http, server, location, if in location
add_traileradd_trailer name value [always];-http, server, location, if in location
addition_typesaddition_types mime-type ...;addition_types text/html;http, server, location
aioaio on | off | threads[=pool];aio off;http, server, location
aio_writeaio_write on | off;aio_write off;http, server, location
aliasalias path;-地点
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_browserancient_browser string ...;-http, server, location
ancient_browser_valueancient_browser_value string;ancient_browser_value 1;http, server, location
apiapi [write=on|off];-location
auth_basicauth_basic string | off;auth_basic off;http, server, location, limit_except
auth_basic_user_fileauth_basic_user_file file;-http, server, location, limit_except
auth_httpauth_http URL;-mail, server
auth_http_headerauth_http_header header value;-mail, server
auth_http_pass_client_certauth_http_pass_client_cert on | off;auth_http_pass_client_cert off;mail, server
auth_http_timeoutauth_http_timeout timeauth_http_timeout 60s;mail, server
auth_jwtauth_jwt string [token=$variable] | off;auth_jwt off;http, server, location, limit_except
auth_jwt_claim_setauth_jwt_claim_set $variable name ...;-http
auth_jwt_header_setauth_jwt_header_set $variable name ...;-http
auth_jwt_key_fileauth_jwt_key_file file;-ttp, server, location, limit_except
auth_jwt_key_request

下一主题NGINX 变量