I recently migrated my site from WordPress to Ghost to try it out, perhaps I will give my opinions of Ghost in another post. I wanted to have comments on this blog however unlike WordPress, Ghost doesn’t have native commenting. Therefore I needed a third party option. I first considered Disqus but I read a few bad things about their practices so they were out of the picture. Enter Commento.
Commento is an open source, lightweight, privacy friendly commenting solution. Commento looked like it fit the bill for my purposes so I thought I would try it out. They offer a hosted solution for a monthly cost as well as an option to self-host. Recently I have been self hosting a lot more things so I thought I would try hosting Commento as well. I set up Commento behind a Nginx proxy with a local Postgres database on a Ubuntu 19.10 server.
Deploying Commento
The documentation for Commento is quite good however its missing a steps that I needed to do for my setup. So I will share what I had to do below. There is a couple of options for deployment, you can download the release binaries, use a docker image or compile the source yourself. I tried to deploy the docker image and connect it to a local Postgres database but I was having too many issues so I just ending up deploying the release binaries and setting up a service which turned out to be quite easy.
First I had to create a new database for Commento on my Postgres instance. I also added a user for commento to use to access the database. Code below.
sudo -u postgres psql
CREATE DATABASE commento;
CREATE USER commento WITH PASSWORD 'commento';
quit
After that I downloaded the release binaries and extracted them to the location where they would run from, eg. /usr/bin/commento. Commento gets all its configuration from environment variables. So I then had to set up a service for Commento to keep it running and have the correct environment variables set. I have provided an example systemd unit file below for Ubuntu, you will need to change the variables according to your environment. This file needs to be created and saved in /etc/systemd/system
with the name commento.
[Unit]
Description=Commento daemon service
After=network.target postgresql.service
[Service]
Type=simple
ExecStart=/usr/bin/commento
Environment=COMMENTO_ORIGIN=https://commento.example.com
Environment=COMMENTO_PORT=8080
Environment=COMMENTO_POSTGRES=postgres://commento:commento@localhost:5432/commento?sslmode=disable
Environment=COMMENTO_SMTP_HOST=smtp.example.com
Environment=COMMENTO_SMTP_PORT=587
Environment=COMMENTO_SMTP_USERNAME=commento@example.com
Environment=COMMENTO_SMTP_PASSWORD=commento
Environment=COMMENTO_SMTP_FROM_ADDRESS=commento@example.com
[Install]
WantedBy=multi-user.target
Once that file has been create you can use sudo service commento start
to start the service and check it is running with sudo service commento status
. Once you have confirmed it is all working we can then begin to set up the nginx proxy configuration.
First I set up a subdomain at my domain registrar. Then I got a SSL certificate for my Commento subdomain from LetsEncrypt. After that, I used the below configuration to proxy requests coming into Nginx to the local Commento service. You will obviously need to change the domain names as well as SSL certificate locations as well as listen directives as need be. You may also need to change the port you are running the Commento service on if you changed it in the service file.
# Redirect http to https
server {
listen 80;
listen [::]:80;
server_name commento.example.com;
return 301 https://commento.example.com$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name commento.example.com;
location / {
proxy_set_header HOST $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
}
ssl_certificate /etc/letsencrypt/live/commento.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/commento.example.com/privkey.pem;
}
Once the Nginx configuration is deployed you should be able to access the admin page using the sub/domain you have set up. Then you can proceed with the configuration of Commento and add it to your site.
I have just added it to my Ghost footer injection which kinda places it in a weird place due to Ghost’s templating. However, it looks good enough for now. But maybe in the future I will play with it some more to get it looking nicer.
Thanks for reading, please leave a comment to try out Commenot below. Or if you have any questions about the above steps please also leave a comment and I will try help you out.