标签:
Nginx的return关键字属于HttpRewriteModule模块:
语法:return http状态码 默认值:无 上下文:server,location,if 该指令将结束执行直接返回http状态码到客户端. 支持的http状态码:200, 204, 400, 402-406, 408, 410, 411, 413, 416 , 500-504,还有非标准的444状态码.
使用方法:
#不符合规则的返回403禁止访问
location /download/ { rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 break; return 403; }
小技巧
这些小技巧都是wiki里没有介绍的,而系统却是支持的。
如下配置文件:
server { server_name test.vincentguo.cn; listen 80; location / { add_header Content-Type "text/plain;charset=utf-8"; return 200 "Your IP Address:$remote_addr"; } }
执行请求:
$ curl -i http://test.vincentguo.cn
返回内容如下:
HTTP/1.1 200 OK Server: nginx/1.0.13 Date: Thu, 10 May 2012 10:01:15 GMT Content-Type: application/octet-stream Content-Length: 30 Connection: keep-alive Content-Type: text/plain;charset=utf-8 Your IP Address:123.128.217.19
标签:
原文地址:http://www.cnblogs.com/apanly/p/5571466.html