Nginx conf文件是什么语言? [英] What language are nginx conf files?

查看:1041
本文介绍了Nginx conf文件是什么语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Nginx配置文件中写一些更复杂的条件,但是我不确定语法,也找不到文档来描述您可以在示例的基础上做些什么,而我似乎找不到在Nginx论坛或邮件列表上.

例如,我是否有可能出现unless条件?

解决方案

所以我是nginx的新手,并且有同样的问题.事实证明,上述语言的语法既是自定义的,也实际上很简单.语法为捕获在NGINX文档的一个部分中,为方便起见在此重复:

nginx由受指令控制的模块组成 在配置文件中指定.指令分为 简单指令和块指令.一个简单的指令包括 名称和参数之间用空格分隔,并以分号结尾 (;).块指令与简单指令的结构相同, 但是它以分号结尾而不是分号 用大括号({和})括起来的说明.如果一个块指令可以 花括号内还有其他指令,称为上下文(示例: 事件,http,服务器和位置).

在任何上下文之外放置在配置文件中的指令 被认为是在主要情况下.事件和http 指令位于主上下文中,服务器位于http中,位置位于 服务器.

#号后的其余行被视为注释.

总结:NGINX配置文件中的所有内容都是指令,其中可能引用了变量.所有指令均此处按字母顺序列出,而所有变量均为 https://devdocs.io/,尤其是 解决方案

So I'm a newbie to nginx, and had this same question. Turns out the syntax of the language as mentioned above is both custom and actually quite simple. The syntax is captured in a section in the NGINX docs, and repeated here for convenience:

nginx consists of modules which are controlled by directives specified in the configuration file. Directives are divided into simple directives and block directives. A simple directive consists of the name and parameters separated by spaces and ends with a semicolon (;). A block directive has the same structure as a simple directive, but instead of the semicolon it ends with a set of additional instructions surrounded by braces ({ and }). If a block directive can have other directives inside braces, it is called a context (examples: events, http, server, and location).

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 in http, and location in server.

The rest of a line after the # sign is considered a comment.

In summary: Everything in an NGINX config file is a directive which may reference a variable. All directives are listed alphabetically here, and all variables are listed alphabetically here. NGINX configuration is driven by modules that each implement a certain piece of functionality, and each module contributes directives and variables that become available for use within the config. That's it.

That is why even if -- which looks like a keyword like in a traditional programming language -- is actually just a directive contributed by the ngx_http_rewrite_module module.

Hope this helps!

PS - Also check out https://devdocs.io/, and specifically https://devdocs.io/nginx, for a much improved way to search/use the NGINX documentation.

这篇关于Nginx conf文件是什么语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆