Nginx 配置 返回字符串

by Web全栈工程师 on 2012 年 09 月 11 日

返回字符串 nginx配置如下:

server {
    server_name  www.magentonotes.com;
    listen  80;
    location / {
        default_type text/html;
        add_header Content-Type "text/plain;charset=utf-8";
        return 200 "Your IP Address:$remote_addr";
    }
}	

返回JSON,nginx配置如下:

server {
	server_name www.magentonotes.com;
	listen 80;
	location ~ ^/get_json {
	    default_type application/json;
	    add_header Content-Type "text/plain;charset=utf-8";
	    return 200 '{"status":"success","result":"nginx json"}';
	}

原创文章,转载请注明:转载自Web开发笔记 | Nginx 配置 返回字符串

本文链接地址:http://www.magentonotes.com/nginx-config-return-json.html

Comments on this entry are closed.

Previous post:

Next post: