Port Forwarding on Snap Installation Always Breaks

Nextcloud version (eg, 20.0.7): 20.0.7
Operating system and version (eg, Ubuntu 20.04.2): Ubuntu 20.04.2

The issue you are facing:
I experimented with many installs/ reinstalls of NC 20 on Ubuntu 20 using Snap. How do I change the default ports of 80, 443 to 82, 444 ? I’ve tried the commands below. They seem to break access and then I have to reinstall NC…

Steps to replicate it. Each step was tried separately, not together

  1. sudo snap set nextcloud ports.http=82
    sudo snap set nextcloud ports.https=444

  2. iptables -t nat -A PREROUTING -p tcp --dport 444 -j DNAT --to-destination 127.0.0.1:443
    iptables -t nat -A PREROUTING -p tcp --dport 84-j DNAT --to-destination 127.0.0.1:80

Is there a guide that shows all other places to change (apache, etc)?

Why are you doing this? If you’ve changed the listening port, directing it back to the original port would not work (not to mention it’s completely unnecessary).

Hey Karl, thanks for feedback, the DNAT settings was just a desperate attempt, after many reinstalls, to get the NC server to respond to port 82 and 444 instead of 80 and 443 using the recommended directions:

sudo snap set nextcloud ports.http=82
sudo snap set nextcloud ports.https=444

Was hoping someone might have some guidance on the next step… Obviously the “why are doing this” question is self-evident. I’m throwing everything at it… Has anyone successful changed the listening ports on a snap install?

Many people have successfully changed the ports using the commands you posted. I don’t use the snap version personally.

So are you saying you put in the above commands and the ports don’t change? Or you get some sort of error?

Yes, if working on the internal network, accessing NextCloud at http://192.168.1.50 and https://192.168.1.50 works.

After applying these commands:

sudo snap set nextcloud ports.http=82
sudo snap set nextcloud ports.https=444

http://192.168.1.50:82 and https://192.168.1.50:444 does not work. Furthermore, trying to reset the ports back to normal no longer allow any access… The I have to reinstall NC to get it to work…

According to the snap documentation, that is exactly how it should be done, and many others have successfully changed the ports like this, so I’m not sure what the issue could be.