Based on deadpool-postgres example.
Adapted to Ntex and Rustls.
This example combines deadpool-postgres with a ntex webservice to implement a simple API service that responds with JSON read from PostgreSQL.
Instructions to run example, see https://github.com/bikeshedder/deadpool/blob/master/examples/postgres-actix-web/README.md#running-the-example.
- Create postgres
deadpooldb. - Load data
fixture.sql - Create
.envfile
cargo run
Copy certificates to postgres directory or configure the path to them in postgres.conf.
postgresql.conf
ssl = on
ssl_cert_file = 'server.crt'
ssl_key_file = 'server.key'
ssl_ca_file = 'ca.crt'
pg_hba.conf
# Only allow SSL connections
hostssl all all 127.0.0.1/32 md5
hostssl all all ::1/128 md5
hostssl all all 0.0.0.0/0 md5
Verify/identify client and server
pg_hba.conf
# Only allow SSL connections
hostssl all all 127.0.0.1/32 cert clientcert=verify-full
hostssl all all ::1/128 cert clientcert=verify-full
hostssl all all 0.0.0.0/0 cert clientcert=verify-full
Connect with client psql
$ psql "host=127.0.0.1 port=5432 dbname=deadpool user=postgres sslmode=verify-full sslcert=client.crt sslkey=client.key sslrootcert=ca.crt"