FRiCKLE / ngx_postgres

upstream module that allows nginx to communicate directly with PostgreSQL database.
http://labs.frickle.com/nginx_ngx_postgres/
BSD 2-Clause "Simplified" License
545 stars 122 forks source link

Support for multiple database connections #11

Closed shantanoo closed 12 years ago

shantanoo commented 12 years ago

Currently only one upstream database is supported. In the 'http' section of the nginx.conf file. For different 'server' section in nginx.conf file, how to get different upstream database?

e.g.

http {

upstream database {
    postgres_server  127.0.0.1 dbname=<dbname> user=<user> password=<password>;
}   

....

http {

server {
    location = /numbers/ {
        postgres_pass     database;
        rds_json          on; 

        postgres_query    HEAD GET  "SELECT * FROM <table>";
    }   
    server_name vhost1;
    upstream database {
        postgres_server  127.0.0.1 dbname=<dbname> user=<user> password=<password>;
    }   
}
server {
    location = /alphabets/ {
        postgres_pass     database;
        rds_json          on; 

        postgres_query    HEAD GET  "SELECT * FROM <another_table>";
    }   
    server_name vhost2;
    upstream database {
        postgres_server  127.0.0.1 dbname=<another_dbname> user=<another_user> password=<another_password>;
    }   
}

...

PiotrSikora commented 12 years ago

Just use different upstream names:

upstream database1 { ... }
upstream database2 { ... }
shantanoo commented 12 years ago

Thanks. I assumed 'database' as keyword instead of the connection name.