Nginx 从重定向规则中排除目录
Nginx excluding directory from redirect rules
我在 Nginx 中有以下 .conf
location / {
if ($uri !~ ^/front/? ){
include ez_params.d/ez_rewrite_params last;
}
include common_auth.conf.inc;
location ~ ^/(index|index_(rest|cluster|treemenu_tags))\.php(/|$) {
#bunch of rules here
}
}
我在这里要做的是从所有 EzPublish 重写规则中排除 /front/ 文件夹。然而,这不仅不起作用,它甚至在尝试加载此文件时给我一个错误:
"nginx: [emerg] "include" 指令在 /etc/nginx/conf.d/staging-preview.conf:51 中是不允许的
nginx: 配置文件 /etc/nginx/nginx.conf 测试失败
我发现使用 "if" 几乎没有完成,请参阅 http://wiki.nginx.org/IfIsEvil ,但我不明白我应该做什么。
只需创建单独的位置块,include/exclude 随心所欲。您可以根据需要重复 "includes"
例如:
location ~ ^/front/? {
# Here we only include the common_auth file
include common_auth.conf.inc;
}
location ~ ^/(index|index_(rest|cluster|treemenu_tags))\.php(/|$) {
# Here we also only include the common_auth file
include common_auth.conf.inc;
....
}
location / {
# Here we also include the common_auth file
# As well as the ez_rewrite_params
include ez_params.d/ez_rewrite_params;
include common_auth.conf.inc;
}
请注意,您不使用 "last" 来包含文件
我在 Nginx 中有以下 .conf
location / {
if ($uri !~ ^/front/? ){
include ez_params.d/ez_rewrite_params last;
}
include common_auth.conf.inc;
location ~ ^/(index|index_(rest|cluster|treemenu_tags))\.php(/|$) {
#bunch of rules here
}
}
我在这里要做的是从所有 EzPublish 重写规则中排除 /front/ 文件夹。然而,这不仅不起作用,它甚至在尝试加载此文件时给我一个错误:
"nginx: [emerg] "include" 指令在 /etc/nginx/conf.d/staging-preview.conf:51 中是不允许的 nginx: 配置文件 /etc/nginx/nginx.conf 测试失败
我发现使用 "if" 几乎没有完成,请参阅 http://wiki.nginx.org/IfIsEvil ,但我不明白我应该做什么。
只需创建单独的位置块,include/exclude 随心所欲。您可以根据需要重复 "includes"
例如:
location ~ ^/front/? {
# Here we only include the common_auth file
include common_auth.conf.inc;
}
location ~ ^/(index|index_(rest|cluster|treemenu_tags))\.php(/|$) {
# Here we also only include the common_auth file
include common_auth.conf.inc;
....
}
location / {
# Here we also include the common_auth file
# As well as the ez_rewrite_params
include ez_params.d/ez_rewrite_params;
include common_auth.conf.inc;
}
请注意,您不使用 "last" 来包含文件