This is roughly what I did to have an Nginx web server on the same machine as dockerized Mailcow
server {
listen 80;
server_name mail.xxxxx.com;
root /var/www/mail.xxxxx.com;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name mail.xxxxx.com;
charset UTF-8;
access_log /var/log/nginx/access.mail.xxxxx.com;
error_log /var/log/nginx/error.mail.xxxxx.com;
include snippets/error_pages.conf;
ssl_certificate /etc/letsencrypt/live/mail.xxxxx.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mail.xxxxx.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams-2048.pem;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_buffering off;
include /etc/nginx/proxy_params;
}
}
server {
listen 80;
listen [::]:80;
server_name mail.xxxxx.com;
return 301 https://mail.xxxxx.com$request_uri;
}
The problem is that Mailcow can no longer use port 80 to update it's ssl certificates that are used by postfix and dovecot. Instead certbot puts them in /etc/letsencrypt/live, so I wrote the following script that tests if the certificates there and in mailcow are the same, if not copies them over and reloads mailcow. It runs from crontab twice daily.
#!/bin/bash
file1="/etc/letsencrypt/live/mail.xxxxx.com/fullchain.pem"
file2="/opt/mailcow-dockerized/data/assets/ssl/cert.pem"
if cmp "$file1" "$file2" | grep "differ"; then
# copy ssl files
cp /etc/letsencrypt/live/mail.xxxxx.com/fullchain.pem \
/opt/mailcow-dockerized/data/assets/ssl/cert.pem
cp /etc/letsencrypt/live/mail.xxxxx.com/privkey.pem \
/opt/mailcow-dockerized/data/assets/ssl/key.pem
# reload mailcow
/usr/bin/docker exec $(/usr/bin/docker ps -qaf \
name=postfix-mailcow) postfix reload
/usr/bin/docker exec $(/usr/bin/docker ps -qaf \
name=dovecot-mailcow) dovecot reload
fi
ยง