gpt4 book ai didi

nginx - nginx conf 文件是什么语言?

转载 作者:行者123 更新时间:2023-12-03 06:06:05 37 4
gpt4 key购买 nike

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

例如,我是否可以有一个 unless 条件?

最佳答案

所以我是 nginx 的新手,也有同样的问题。事实证明,上述语言的语法既是自定义的,而且实际上非常简单。语法为 captured in a section在 NGINX 文档中,为了方便起见,在此处重复:

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.

总结: NGINX 配置文件中的所有内容都是一个指令,它可以引用变量。所有指令均为 listed alphabetically here ,所有变量都是 listed alphabetically here 。 NGINX 配置由模块驱动,每个模块都实现特定的功能,并且每个模块贡献可在配置中使用的指令和变量。就是这样。

这就是为什么即使 if(看起来像传统编程语言中的关键字)实际上也只是 ngx_http_rewrite_module< 贡献的指令/ module .

希望这有帮助!

PS - 另请查看https://devdocs.io/ ,特别是 https://devdocs.io/nginx大大改进了搜索/使用 NGINX 文档的方式。

关于nginx - nginx conf 文件是什么语言?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2936260/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com