# TLS connection - Error: 14 UNAVAILABLE: Connect Failed

**URL:** <https://discuss.dgraph.io/t/tls-connection-error-14-unavailable-connect-failed/8169>\
**Category:** Dgraph Clients\
**Tags:** kind:question, dgraph-js\
**Created:** [February 15, 2019, 5:40pm UTC](https://discuss.dgraph.io/t/tls-connection-error-14-unavailable-connect-failed/8169 "2019-02-15T17:40:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [February 15, 2019, 5:40pm UTC](https://discuss.dgraph.io/t/tls-connection-error-14-unavailable-connect-failed/8169/1 "2019-02-15T17:40:46Z")

</div>

**Moved from GitHub [dgraph-js/50](https://github.com/dgraph-io/dgraph-js/issues/50)**

_Posted by_ [mkucharz](https://github.com/mkucharz):

I’m trying to set up secure GRPC connection. What have I done so far:

- generate certs using `dgraph cert`
- verify fingerprints and certs using open ssl (`openssl verify -verbose -CAfile ca.crt node.crt`)
- check the connection and certs crescents with `openssl s_client -connect 176.9.122.98:9080 -CAfile ca.crt`
- set up connection:

```auto
const rootCert = fs.readFileSync(path.join(__dirname, 'certs', 'ca.crt'))
const clientData = new dgraph.DgraphClientStub(
  '<my_external_machine_IP_address>:9080',
   grpc.credentials.createSsl(rootCert)
)

```

- try to connect: `Error: 14 UNAVAILABLE: Connect Failed`

In addition i configured NGINX grpc proxy, first without SSL (works fine), then with SSL (same error as  
above).

Any ideas what else to check and what can be wrong? Did anyone successfully configured `dgraph-js` to work with TLS?

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [February 20, 2019, 8:43pm UTC](https://discuss.dgraph.io/t/tls-connection-error-14-unavailable-connect-failed/8169/2 "2019-02-20T20:43:48Z")

</div>

[gorjuspixels](https://github.com/gorjuspixels) _commented_ :

It’s working for us (though we’re not using nginx… couldnt set up gRPC and SSL through it successfully).

But anyways, our grpc credentials look like this:

```javascript
grpc.credentials.createSsl(caCrt, clientKey, clientCrt)

```

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [February 20, 2019, 11:56pm UTC](https://discuss.dgraph.io/t/tls-connection-error-14-unavailable-connect-failed/8169/3 "2019-02-20T23:56:29Z")

</div>

[danielmai](https://github.com/danielmai) _commented_ :

@gorjuspixels is right. If the system isn’t configured to trust the root CA generated by `dgraph cert` then you must provide it along with the client certificate and client certificate key to be properly authenticated.

Also, you shouldn’t set `https://` in the address name. The address host and port is sufficient.

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [February 21, 2019, 10:25pm UTC](https://discuss.dgraph.io/t/tls-connection-error-14-unavailable-connect-failed/8169/4 "2019-02-21T22:25:25Z")

</div>

[danielmai](https://github.com/danielmai) _commented_ :

There is now example code for connecting dgraph-js and Dgraph with mutual TLS. Please see the TLS example linked in the README:

> **[GitHub - dgraph-io/dgraph-js: Official Dgraph JavaScript client](https://github.com/dgraph-io/dgraph-js#examples)**
>
> Official Dgraph JavaScript client. Contribute to dgraph-io/dgraph-js development by creating an account on GitHub.

> <https://github.com/dgraph-io/dgraph-js/tree/master/examples/tls>
>
> //github.com/dgraph-io/dgraph-js/tree/master/examples/tls

Try out the example feel free to re-open this issue if you’re still having the issue.

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [February 24, 2019, 10:55pm UTC](https://discuss.dgraph.io/t/tls-connection-error-14-unavailable-connect-failed/8169/5 "2019-02-24T22:55:31Z")

</div>

[mkucharz](https://github.com/mkucharz) _commented_ :

@danielmai `https` was left after testing `dgraph-js-http`… I’ve updated original question (because I still had a problem even without https).

Anyway, your @gorjuspixels and @danielmai responses were very helpful.

It turned out that the problem was in common name of the certificate… I forgot to generate it with additional host names, more info here:  
[https://docs.dgraph.io/deploy#file-naming-conventions](https://docs.dgraph.io/deploy#file-naming-conventions)

Leaving this message mainly for other people lost in similar place 🙂

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [July 11, 2020, 4:17am UTC](https://discuss.dgraph.io/t/tls-connection-error-14-unavailable-connect-failed/8169/6 "2020-07-11T04:17:30Z")

</div>

Closed on July 11, 2020, 4:17am UTC


