nginx-0.8.42 的一个新feature

nginx 0.8.42 有个新功能:

Feature: a text answer may be added to a “return” directive. (via nginx.org )

这个功能其实很有趣,当然自己写也不难,官方实现了就最好。

找了下,找不到相关的配置说明,只好自己摸索一下吧。一试就出来了,真神奇,哈哈。

三步走(./configure ; make ; make install)安装好 nginx 后,在配置上加一段:

location /iloveu/ {
return 200 “iloveu” ;
}
同时把
default_type  application/octet-stream;
修改为
default_type  text/plain;
如果是前者的话,不会看到字符串,而会下载的噢。
启动 nginx 后,curl -i http://127.0.0.1/iloveu/
HTTP/1.1 200 OK
Server: nginx/0.8.42
Date: Sun, 27 Jun 2010 18:44:04 GMT
Content-Type: text/plain
Content-Length: 3
Connection: keep-alive
iloveu
就这样玩玩吧。

Submit a Comment