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

nginx nginx returns json

WBOY
Release: 2016-07-29 08:42:17
Original
1694 people have browsed it

1. Format

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

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;
    }
Copy after login

#query.map
arg=querytest   1;
arg=query       0;
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template