Nginx location中的@

296次阅读
没有评论

共计 466 个字符,预计需要花费 2 分钟才能阅读完成。

Nginx location中的@

nginx中的location用来做url匹配并处理,以往都是location /xxx/xxx,然而最近博主看到一个居然有这种写法的配置:

error_page 404 = @fallback;
location @fallback {
    proxy_pass http://www.linuxhub.org;
}

没想到居然还有@….,查询了下该用法:

@:用于定义一个location块,则该块不能被外部client访问,只能被nginx内部配置指令所访问

改造一下上面404实例

    error_page 404 = @fallback;
    location @fallback {
        default_type application/json;
        charset utf-8;
        return 200 '{"site":"xadocker.cn","status":"404"}';
    }

测试访问下

[root@nginx-cluster conf.d]# curl openresty.xadocker.cn/abcdefg
{"site":"xadocker.cn","status":"404"}

正文完
 
xadocker
版权声明:本站原创文章,由 xadocker 2020-04-11发表,共计466字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)