# Recipe: Using Let's Encrypt for TLS certificates with \`mattermost-docker\`

**URL:** <https://forum.mattermost.com/t/recipe-using-lets-encrypt-for-tls-certificates-with-mattermost-docker/7596>\
**Category:** Recipes\
**Created:** [July 2, 2019, 9:52pm UTC](https://forum.mattermost.com/t/recipe-using-lets-encrypt-for-tls-certificates-with-mattermost-docker/7596 "2019-07-02T21:52:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulrothrock](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/paulrothrock/32/2967_2.png) [@paulrothrock](https://forum.mattermost.com/u/paulrothrock)\
**Post date:** [July 2, 2019, 9:52pm UTC](https://forum.mattermost.com/t/recipe-using-lets-encrypt-for-tls-certificates-with-mattermost-docker/7596/1 "2019-07-02T21:52:50Z")

</div>

## Problem

You’re setting up Mattermost using Docker in production and want to use a Let’s Encrypt certificate. When you attempt to configure this via the System Console you get the following error:

```auto
p_1 | {"level":"error","ts":1562088526.1421692,"caller":"commands/server.go:77","msg":"listen tcp :443: bind: permission denied"} 

```

## Solution

**Note:** This assumes you have a valid domain name for your Mattermost server. Replace `mattermost.example.com` with your domain name. This has also been tested on Ubuntu 18.04, but should work for any version of Linux that supports `docker` and `certbot`.

1. Shut down Mattermost

```auto
cd ~/mattermost-docker
docker-compose stop

```

1. Verify the following values in `~/mattermost-docker/volumes/config/config.json`

```auto
“SiteURL”: “https://mattermost.example.com”,
“ListenAddress”: “:8000”,
“ConnectionSecurity”: “”,
“UseLetsEncrypt: false,
“Forward80To443” false,

```

1. Install `certbot` from Let’s Encrypt

```auto
sudo apt-get install certbot

```

1. Run certbot generate the certificate and key

```auto
sudo certbot certonly —standalone -d mattermost.example.com

```

Then follow the onscreen prompts to generate your new certificate

1. Copy your certs to the correct path:

```auto
sudo cp /etc/letsencrypt/live/mattermost.example.com/fullchain.pem /home/ubuntu/mattermost-docker/volumes/web/cert/cert.pem

sudo cp /etc/letsencrypt/live/mattermost.example.com/privkey.pem /home/ubuntu/mattermost-docker/volumes/web/cert/key-no-password.pem 

```

1. Start up docker in daemon mode so its stays running after logout

```auto
cd ~/mattermost-docker
docker-compose up -d

```

Your site should now be available on [https://mattermost.example.com/](https://mattermost.example.com/)

## Discussion

Because the default `mattermost-docker` instructions include an Nginx reverse proxy server that runs on ports 80 and 443, and forwards requests to the Mattermost server that’s listening on port 8000. However, in order for Mattermost to handle the Let’s Encrypt negotiation it needs to run on 80 and 443 so it can respond to the authentication challenge.

If you have any questions or improvements to this recipe please let me know!

---

<div class="post-metadata">

**Author:** ![Claas](https://avatars.discourse-cdn.com/v4/letter/c/919ad9/32.png) [@Claas](https://forum.mattermost.com/u/Claas)\
**Post date:** [February 20, 2020, 1:02pm UTC](https://forum.mattermost.com/t/recipe-using-lets-encrypt-for-tls-certificates-with-mattermost-docker/7596/2 "2020-02-20T13:02:46Z")

</div>

Does Mattermost renew the certificate once this is running?

---

<div class="post-metadata">

**Author:** ![paulrothrock](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/paulrothrock/32/2967_2.png) [@paulrothrock](https://forum.mattermost.com/u/paulrothrock)\
**Post date:** [March 18, 2020, 8:22pm UTC](https://forum.mattermost.com/t/recipe-using-lets-encrypt-for-tls-certificates-with-mattermost-docker/7596/3 "2020-03-18T20:22:59Z")

</div>

@Claas Mattermost doesn’t renew the certificate every month, you’ll have to do that manually. To set up automatic renewal you can install Nginx and follow [these instructions](https://docs.mattermost.com/install/config-ssl-http2-nginx.html?highlight=encrypt)
