Chinaunix首页 | 论坛 | 博客
  • 博客访问: 255740
  • 博文数量: 159
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1619
  • 用 户 组: 普通用户
  • 注册时间: 2016-01-10 19:58
文章分类

全部博文(159)

分类: Web开发

2016-06-08 22:40:43

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.54php.cn;
    listen  80;
    location / {
        add_header Content-Type "text/plain;charset=utf-8";
        return 200 "Your IP Address:$remote_addr";
    }
}

执行请求:

$ curl -i 

返回内容如下:

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

原文地址:标签:      curl   

智能推荐

阅读(954) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~