我有一个包含3个参数的数据库:name,http_host和http_port
stardb=# select name, http_host, http_port from data ;
name | http_host | http_port
-------+---------------+-----------
user2 | 127.0.0.1 | 80
user1 | 192.x.x.x. | 80
我想在我的nginx服务器中创建一个循环,这样每个名称都会生成一个proxy_pass http:// $ http_host:$ http_port。
这就是我的所作所为:
location /getIp {
default_type 'text/plain';
rds_json on;
set $name '';
postgres_pass database;
postgres_query "SELECT http_host FROM data WHERE name = \'$name\'";
postgres_output rds;
}
location /getPort {
default_type 'text/plain';
rds_json on;
set $name '';
postgres_pass database;
postgres_query "SELECT http_port FROM data WHERE name = \'$name\'";
postgres_output rds;
}
location /$name {
ip = ngx.location.capture("/getIp", {
method = ngx.HTTP_GET
})
port = ngx.location.capture("/getPort", {
method = ngx.HTTP_GET
})
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://$ip:$port;
}
但是我没有看到如何建立循环来浏览数据库。