nginx捕获URL并直接返回
需求
对于包含了get-tip-msg和get-robot-state的URL进行捕获,然后由nginx直接返回查询参数中callback的内容。
1.
robotapi.fdcyun.com/v1/erp/get-tip-msg?erpversion=ERP352&userid=ba599913-2dee-439a-94eb-006e48b8702e&callback=jQuery1102002275843247537146_1513789204858&_=1513789204859
2.
robotapi.fdcyun.com/v1/erp/get-robot-state?erpversion=ERP352&userid=ba599913-2dee-439a-94eb-006e48b8702e&callback=jQuery1102002275843247537146_1513789204856&_=1513789204857
nginx的配置文件
server {
listen 9010 ;
server_name mycloud-test.abcn.com;
index index.html index.hml;
location ~ ^/v1/erp/get-robot-state {
default_type application/javascript;
add_header Content-Type 'application/javascript; charset=UTF-8';
set $s1 $arg_callback;
return 200 $s1("0");
}
location ~ ^/v1/erp/get-tip-msg {
default_type application/javascript;
add_header Content-Type 'application/javascript; charset=UTF-8';
set $s1 $arg_callback;
return 200 $s1("");
}
}
访问的效果
- 当访问链接1时,返回的结果
jQuery1102002275843247537146_1513789204858("");
- 当访问链接2时,返回的结果
jQuery1102002275843247537146_1513789204856("0");