Skip to content

nginx返回文本和json格式

Published:

1.返回json格式

location /json {
    default_type application/json;
    return 200 '{"status":"success","message":"hello world!"}';
}

2.返回html

location /html {
    default_type text/html;
    return 200 '<html><head><title>html</title></head><body><h1>Hello World!</h1></body></html>';
}

3.返回纯文本

location /text {
    default_type text/plain;
    return 200 'hello world!';
}