mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2026-04-26 01:45:54 +03:00
[GH-ISSUE #779] nginx proxy manager in fron of mailcow #656
Labels
No labels
awaiting feedback
bug
cannot reproduce
dns provider request
duplicate
enhancement
enhancement
enhancement
good first issue
help wanted
invalid
need more info
no certbot plugin available
product-support
pull-request
question
stale
troll
upstream issue
v2
v2
v2
v3
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/nginx-proxy-manager-NginxProxyManager#656
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @cjohn001 on GitHub (Dec 17, 2020).
Original GitHub issue: https://github.com/NginxProxyManager/nginx-proxy-manager/issues/779
Hello together,
I am currently trying to figure out if I can use nginx proxy manager in fron of my mailcow installation. The question I have is related to ssl certificates generated with letsencrypt. In case I use proxy manager to obtain ssl certificates I would need to be able to execute a posthook script each time the certificates are updated. Is this possible and how could I do it?
I need to provide the ssl certificates to my mailcow installation (which uses the certificates with postfix,dovecat and internal nginx containers) and after I copied the certificates I need to run a script to restart the relevant mailcow containers.
would be great if someone could show me directions
@3xitsharp commented on GitHub (Dec 27, 2020):
Duplicate issue and possible workaround https://github.com/jc21/nginx-proxy-manager/issues/690
To answer your question. NPM provides acme hook directories in its installation path. Simply scp the certificate over to your mailcow host and restart mailcow containers.
For my workaround i've completely disabled HTTP validation in NPM since i only use DNS validation anyways.
/etc/nginx/conf.d/include/letsencrypt-acme-challenge.confinto the NPM container to prevent the "duplicate location" error.Define location
^~ /.well-known/acme-challenge/Forward Hostname / IP
mailcow.ip.address/.well-known/acme-challenge/Scheme / Forward Port
http / 80SKIP_HTTP_VERIFICATION=yand most likelySKIP_IP_CHECK=ydocker-compose restart acme-mailcowand watch logs for successful certificate generationdocker-compose logs --tail=200 -f acme-mailcow@meinradr commented on GitHub (Aug 24, 2021):
I do have the same issue. Could someone please explain what acme renewal hooks are and how to use them. It is also not clear which certificate I have to copy since they all appear to have arbitrary names.
@LucaOverflow commented on GitHub (Aug 31, 2021):
NPM automatically calls bash scripts in those mentioned hook directorys. So you can write a script that copies your certificates to another server via scp. One hint: NPM will call the scripts in those directories for every certificate and as far as I know you cannot configure it otherwise. So either use the deploy hook directory since you can use the environment variables
$RENEWED_DOMAINSand$RENEWED_LINEAGEto do domain/certificate specific things or edit the /data/letsencrypt/renewal/npm-x.conf and add apost_hookline linking to a script file in a different location.The certificate number can be seen in the UI. Just go to the SSL Certificates site and click the tree dots of your certificate. The popup will show you the number.
@lriley2020 commented on GitHub (Jun 1, 2022):
I'm also having the same issue: I've got as far as copying the certificates over with the renew hook, but I'm not sure how to restart the mailcow containers afterwards, as the renew hook script gets executed in the nginx proxy manager containter, rather than the host. Does anyone know how I can restart the containers as described here from the nginx proxy manager container?
@LucaOverflow commented on GitHub (Jun 1, 2022):
Yes, but note, that this should only be run in a locked down environment, since it requires root access over ssh. I'm sure there are better solutions out there, but this is my solution:
I'm using sshpass which allows me to run a script on the mailcow container, that restarts the services.
Sidenote:
For this script to work it needs to be placed in the deploy hooks directory
@lriley2020 commented on GitHub (Jun 1, 2022):
Thanks so much for that @LucaOverflow! I rewrote the script slightly to avoid installing the extra sshpass package and enabling root ssh login and it worked perfectly! I also actually ended up specifying the script with the
post_hookdirective inrenewals/npm-xx.conf, just so the script wasn't called each time.Just adding it here in case anyone else has the same issue:
ssh_update.sh (place somewhere in the host machine):
@LucaOverflow commented on GitHub (Aug 16, 2022):
Small Update:
The Script stopped working for me because the Certificate Number has two digits in my Installation now. The Fix is to exchange the
?to a*in the File Selector.So in the Case of the Script I posted before:
Note this doesn't include the Imrovements of @lriley2020's Script. But you can just swap the Questionmarks there, too.
@lriley2020 commented on GitHub (Aug 19, 2022):
Thanks for that @LucaOverflow! I hadn't run into that issue yet, so great to have someone else find the issue before it happened to me!
@vspaziani commented on GitHub (Jul 25, 2023):
Ok I am going to give this a shot since there was the question from @LucaOverflow. This is what worked for me. If you are trying to follow @lriley2020's Script, myself being a novice had to figure a couple things out... follow these instructions: (there is no problem with double digit certificate numbers since they are hard coded into the script)
ssh-keygen -t rsato generate the needed keys for SSH so that it does not require a password for SCP2a. open your docker-compose.yml and look at the letsencrypt mapping for the container. it should look something like "./letsencrypt:/etc/letsencrypt" which means that docker is mapping ./letsencrypt (on the local machine) to "/etc/letsencrypt" (inside the container)
2b. copy the file specified in step 2 to named /something/id_rsa to a location inside ./letsencrypt (using my previous example)
ssh-copy-id _username_@_mailcow_IP_this will copy the public key to your mail cow host4.create a script in "/letsencrypt/renewal-hooks/post/" using my previous example address from step 2a
5a.look at the cert number by clicking on the three dots in the NPM web page, at the top of that popup it will give you a cert number
5b.modify anywhere there is npm-10 in the first script from @lriley2020 with npm-(cert number from 5a)
5c. /path/to/privatekey should be the address you copied the file to on the host machine noting that the actual mapping needs to point with reference to inside the container. For example. if I copied the file to ./letsencrypt/Renew/Fancyscript.sh on my host machine, the docker container will have it at "/etc/letsencrypt//Renew/Fancyscript.sh"
post_hook = /etc/letsencrypt/renewal-hooks/post/(script name from step 4)"Special thanks to both @LucaOverflow and @lriley2020. with your point in the right direction I got it working.
@lriley2020 commented on GitHub (Jul 25, 2023):
Seems like quite a few people are trying to find a solution to the same problem, so I thought I would share my updated workaround a year later. I'm way more happy using this in my homelab because:
How to set up:
Edit: noticed just after posting this that none of the paths have been changed, obvs change them to suit your own setup!
/opt/compose-stacks/nginx-proxy-manager/letsencrypt/copy_cert.sh:/opt/compose-stacks/nginx-proxy-manager/letsencrypt/renewal/npm-10.confto ensure our post renewal hook is run. Optional: also add a line to reuse the SSL key during cert renewal. If this is omitted, you will have to edit the TSLA records for your mailcow configuration every time the certificate and key are renewed together (the standard renewal behaviour):/opt/mailcow-cert-restart/mailcow-cert-restart.sh:... and then give it the right perms:
sudo chown root:root /opt/mailcow-cert-restart/mailcow-cert-restart.shsudo chmod 700 /opt/mailcow-cert-restart/mailcow-cert-restart.sh/etc/systemd/system/mailcow-cert-restart.path:/etc/systemd/system/mailcow-cert-restart.service:sudo systemctl daemon-reloadsudo systemctl enable --now mailcow-cert-restartEverything should now hopefully run fine without SSH - fingers crosed ;)
Thanks again @LucaOverflow, your script is still running great for me one year later!
@Jackk91 commented on GitHub (Jun 19, 2024):
thanks @lriley2020
@protonaut commented on GitHub (Jul 23, 2024):
I followed your instruction. But I don't know how to get the account ID from letsencrypt for
/opt/compose-stacks/nginx-proxy-manager/letsencrypt/renewal/npm-10.confaccount = xxxxxxxxxxxxxxxxxxxxxx
Any quick help? Thanx
@lriley2020 commented on GitHub (Jul 23, 2024):
I just used the xxxxxx to censor my file so that other people can't see my LE account ID. It should have already been written automatically to the config file by NPM - all you are doing is adding a line to this file. Make sure that you double check the cert number in the NPM interface (click on 3 dots) and then check you are looking in the corresponding directory for this certificate.