nginx扩展直接生成应用,不用通过编程语言,实例
来源:互联网 发布:php学java要多久 编辑:程序博客网 时间:2024/06/11 02:35
最近听说淘宝开发了很多nginx的扩展,这些扩展可以独立与编程语言直接开发各种应用,下面看看例子:
This sample demonstrates how to route incoming requests to different MySQL queries based on different combinations of URI query arguments, preserving streaming output capabilities provided byDrizzleNginxModule and RdsJsonNginxModule.
这个例子是演示通过路由url请求来查询mysql,这种通过不同的Url查询字符串来产生字符输出的能力是通过DrizzleNginxModule和RdsJsonNginxModule这两个nginx扩展实现的!
This demo uses the modules DrizzleNginxModule, LuaNginxModule, RdsJsonNginxModule, and SetMiscNginxModule bundled by OpenResty.
这个实例中用到的扩展:DrizzleNginxModule,LuaNginxModule,RdsJsonNginxModule,SetMiscNginxModule是在OpenResty博客中有提到
Here's the complete code listing for our nginx.conf
:
这是完整的配置信息:
worker_processes 2;
error_log logs/error.log warn;
events {
worker_connections 1024;
}
http {
upstream backend {
drizzle_server 127.0.0.1:3306 protocol=mysql
dbname=ngx_test user=ngx_test password=ngx_test;
drizzle_keepalive max=10 overflow=ignore mode=single;
}
server {
listen 8080;
location @cats-by-name {
set_unescape_uri $name $arg_name;
set_quote_sql_str $name;
drizzle_query 'select * from cats where name=$name';
drizzle_pass backend;
rds_json on;
}
location @cats-by-id {
set_quote_sql_str $id $arg_id;
drizzle_query 'select * from cats where id=$id';
drizzle_pass backend;
rds_json on;
}
location = /cats {
access_by_lua '
if ngx.var.arg_name then
return ngx.exec("@cats-by-name")
end
if ngx.var.arg_id then
return ngx.exec("@cats-by-id")
end
';
rds_json_ret 400 "expecting \"name\" or \"id\" query arguments";
}
}
}
And then we start our Nginx server with this configure file and test with our /cats
service like this:
接下来,我们开始测试上面的nginx配置,访问服务器下/cats地址:
$ curl 'localhost:8080/cats'{"errcode":400,"errstr":"expecting \"name\" or \"id\" query arguments"}$ curl 'localhost:8080/cats?name=bob'[{"id":3,"name":"bob"}]$ curl 'localhost:8080/cats?id=2'[{"id":2,"name":null}]
The actual output rows may vary depending on the actual contents in your cats
table anyway.
返回的格式取决于nginx配置信息中指定的格式(指定的是json格式)。
- nginx扩展直接生成应用,不用通过编程语言,实例
- Laravel5中通过SimpleQrCode扩展包生成二维码实例
- 不用编程,能直接计算正确么?
- pbfunc外部函数扩展应用-直接在Datawindow中生成QR二维码
- nginx禁止直接通过IP地址访问
- PB中通过ODBC直接连接数据库,不用注册数据源。
- PB中通过ODBC直接连接数据库,不用注册数据源。
- 静态方法可以直接用类引用,不用实例化
- 通过代理访问nginx和直接访问nginx区别
- ListView实例-直接通过ArrayAdapte…
- 通过文件结构直接生成xls文件
- 通过文件结构直接生成xls文件
- 通过文件结构直接生成xls文件
- 【转载】直接通过User Control生成HTML
- 通过nginx扩展nginx-rtmp-module搭建流媒体服务器
- Android中通过浏览器直接打开应用
- Tomcat 设置直接通过IP访问程序,而不用通过ip+端口+程序
- 通过一个MVC HtmlHelper扩展实例,简单说明扩展步骤
- FORK()函数的理解
- 内建函数
- 自描肖像
- JSP自定义标签(3)
- poj 2421 Constructing Roads
- nginx扩展直接生成应用,不用通过编程语言,实例
- JOJ2520:A special queen
- js的树形结构怎么实现
- oracle中如何移动表空间
- 内建函数解析
- C++程序设计之四书五经/C++学习书籍介绍
- 去掉window关闭时候的弹出框
- SQL Server 2005“备份集中的数据库备份与现有的数据库不同”解决方法
- SGU116