Lek*_*eyn 17 configuration nginx
为了不向后端传递垃圾,我对location指令有一个严格的正则表达式。它看起来像这样:
location ^~ "/(some|stuff|more|bar|etc(-testing)?)/[a-zA-Z0-9]+/...(more|restrict).ext {
# other directives
}
Run Code Online (Sandbox Code Playgroud)
我想在 80 个字符处折叠该行,有没有办法拆分配置?以下结果会导致语法错误,但这是我正在寻找的内容:
location ^~ "/(some|stuff|more|bar|etc(-testing)?)/[a-zA-Z0-9]+/"\
"...(more|restrict).ext" {
# results in a literal newline (%0A) being accepted
location ^~ "/(some|stuff|more|bar|etc(-testing)?)/[a-zA-Z0-9]+/
...(more|restrict).ext" {
Run Code Online (Sandbox Code Playgroud)
我在文档中找不到提示(http://wiki.nginx.org/ConfigNotation也没有http://wiki.nginx.org/HttpCoreModule#location提到折叠线的任何内容)
Mic*_*ton 10
我不认为你能做到这一点。
nginx 平等对待所有空格,因此即使您尝试像这样拆分字符串,并且 nginx 可以按照您想要的方式解析它,您最终会得到一个包含一堆空格的正则表达式,我敢肯定这不是'你想要什么。如果 nginx 无法解析它,这更有可能,您只会收到语法错误。
您只需要忍受几行长行,或者编写不太复杂的正则表达式。