Nginx的return关键字属于HttpRewriteModule模块:
语法:return http状态码
默认值:无
上下文:server,location,if
该指令将结束执行直接返回http状态码到客户端.
支持的http状态码:200, 204, 400, 402-406, 408, 410, 411, 413, 416 , 500-504,还有非标准的444状态码.1.返回错误码
location = /test {
return 403 ;
}2.返回 文本信息和 json
location ^~ /pic {
default_type text/html ;
return 200 'test';
}
location ^~ /pic {
default_type application/json ;
return 200 '{"name":"nanjing_wuxu","result":"success"}';
}说明:如果要想返回字符串,必须要加上状态码,否则会报错。
3.支持变量
location /test {
return 200 "$host $request_uri";
}