1,微信小程序验证
有时候在前端域名当中,接入微信小程序时需要一个 token 的验证,此处的配置可以直接用如下内容进行配置:
location /37og2Z5TwR.txt {
default_type text/html;
return 200 "6831c2a15d3d103c6a1ff356b22b5";
}
此时访问域名,将会返回对应字符串内容。
2,返回字符串
当一个域名需要维护的时候,可以通过如下内容进行公示:
server {
listen 80;
server_name test.confluence.com;
client_max_body_size 50m;
client_body_buffer_size 1024k;
location / {
add_header Content-Type "text/html;charset=utf-8";
return 200 "维护通知 WIKI系统临时紧急维护, 稍后开放。非常抱歉影响您的使用。 04/24/2019 15:19, by OPS
";
}
}
除了这些简单的返回方式,还有其他一些返回方式,这里统一进行一下汇总整理。
3,返回 json
配置如下:
location ~ ^/get_info {
default_type application/json;
return 200 '{"status":"success","result":"hello world!"}';
}
然后请求一下:
$ curl localhost/get_info | jq
{
"status": "success",
"result": "hello world!"
}
4,根据请求参数返回
1,请求文件作为返回参数
location ~ ^/return/(.*)_(d+).html$ {
default_type text/html;
set $string $1;
set $data $2;
return 200 $string:$data;
}
location ~ ^/return/(.*)_(d+).html$ {
default_type text/html;
set $string $1;
set $data $2;
return 200 $string:$data;
}
测试效果:
$ curl localhost/return/test_01.html test:01
2,请求 url 作为返回
location ~ ^/return/(.*)/(d+)$ {
default_type text/html;
set $string $1;
set $data $2;
return 200 $string:$data;
}
测试效果:
$ curl localhost/return/test/123 test:123



