How to setup Nginx

You’re completly right!! It’s working now and uses https

Woohoo :slight_smile: That’s great to hear.
So, we can do a few additional things here, depending on what your next steps are.

The Let’s encrypt recertification will have to be done regularly by you, or, if you want, we can install the certificate from your provider. Is that also a Let’s Encrypt certifiate or is that something with a longer lifetime?

Also, since you mentioned that you want to set up a second domain/mattermost installation, is that something we should address now or is that a topic for another day?

Hey hello again dude,

Well the certificate I dont know if its from Lets encrypt but I think that its different my hosting is in Ionos, but I see in the documentation of lets encrypt that you could enable an auto re-certificate right?

About a second domain and mattermost installation yeah thats something that I want to address now, I want to learn until this step and then… I will do a clean instalation again because right now all my values are by default even passwords

If your hosting provider also only providers Let’s Encrypt for you, we can safely use our own one here, so that’ll be fine.
In order for the certificate to be automatically renewed, you will have to run a certbot container which is configured to work inside the Mattermost setup we have here, but since we do not need to care about that for the next 90 days, I’d leave that for a separate thread in here then in order to keep this one clean.

For the time being, if you need a new certificate: Stop your docker containers, run the scripts/issue-certificate.sh script again and it will renew the certificate (if it’s close to being expired), start the containers again.

For the second Mattermost installation, all you’d have to do here is to follow the deploy instructions here and clone the repo into a NEW directory (we will not touch the existing one we worked on here).

Modify the .env file and change the values for DOMAIN, MATTERMOST_IMAGE_TAG and MATTERMOST_IMAGE according to your needs for the new setup.

Now you need to choose a name for your second instance, just like we did above for the APPNAME, so we’ll assume the following values for now on:

export APPNAME=mattermost2
export DOMAIN=mattermost2.yourdomain.mx

Open the docker-compose.yml file on the new installation and make sure the containers do both have unique names. By default, they’re called mattermost and postgres and that will cause issues if we want to run more of them at the same time. If you do have the container_name setting already, modify it - if it’s not there, insert it. Please be careful with the format, spaces/tabs need to match.

services:
  postgres:
    container_name: mattermost2_postgres
[...]
  mattermost:
    container_name: mattermost2_mattermost

Since we do have the nginx instance in front of all our containers, we do not need the mattermost post to be mapped to the host here, so you could change that in the docker-compose.without-nginx.yml file. It should look like this currently:

services:
  mattermost:
    ports:
      - ${APP_PORT}:8065

You can change that to:

services:
  mattermost:
    expose:
      - ${APP_PORT}

Now you need to fix the hardcoded connection string in the .env file from postgres to your $APPNAME_postres:

sed -i -e 's/@postgres/@'$APPNAME'_postgres/' .env

That’s about it for the new Mattermost deployment, please try to start the containers there now:

docker-compose -f docker-compose.yml -f docker-compose.without-nginx.yml up -d

If that works, you should have two new docker containers running, mattermost2_mattermost and mattermost2_postgres.

Now all you have to do is to create a new certificate for the domain and create a new nginx VHOST, to do so, switch back to the directory of your main Mattermost docker installation and follow these already known steps:

# the name of this application, only letters and numbers, please. The first one will be `mattermost`, this will be your main instance
export APPNAME=mattermost
export DOMAIN=admin.domain.mx

# generate a free Let's Encrypt certificate for this domain
# you will be asked some questions for e-mail addresses and stuff the first time you run it.
# if successful, you should see a respective message at the end telling you that the certificate files
# have been created properly
chmod 755 scripts/issue-certificate.sh
scripts/issue-certificate.sh -d $DOMAIN -o ${PWD}/certs` 

# clone the template to a working configuration, replacing the values
sed -e 's/__APPNAME__/'$APPNAME'/g' -e 's/__DOMAIN__/'$DOMAIN'/g' nginx/conf.d/domain.conf.template > nginx/conf.d/$APPNAME.conf

For the changes to take effect, restart the nginx container:

docker restart nginx_mattermost
1 Like

Hey hello sorry for the delayed response I face some personal Issues I will try this and I will let you know my results

Thank you!!

No rush - take your time, thanks for the update!