Home >Backend Development >PHP Tutorial >nginx nginx returns json

nginx nginx returns json

WBOY
WBOYOriginal
2016-07-29 08:42:171690browse

1. Format

location ~ /query {
     default_type application/json;
     return 200 '{"res":{"code":"0","message":"","value":"$value"}}';
 }

2. default_type application/json; indicates the returned json format, otherwise the browser will open it as a file

3. If you need to return different values ​​based on request parameters, you can consider using map,

    map_hash_bucket_size 128;
    map $args $value{
        default 2;
        include /usr/local/nginx-1.8.1/map/query.map;
    }

#query.map
arg=querytest   1;
arg=query       0;

The above introduces nginx nginx returns json, including nginx content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn