Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Accepted Answer
What I would recommend doing, just to make sure we get the correct setup, is running
ufw disable
Then
ufw reset
The above stops ufw and then resets all rules. With a clean slate, we setup our default policies first.
ufw default deny incoming \
&& ufw default allow outgoing
With those rules in place, we then add the rules we need to work for whatever our purposes are. To start, I recommend allowing SSH in first.
ufw allow 22/tcp
We can then allow application-specific ports, such as 80, 443, 8001, etc. I’ll start with those three.
ufw allow 80/tcp \
&& ufw allow 443/tcp \
&& ufw allow 8001/tcp
We could also run just one command (copy and paste directly)
ufw disable \
&& ufw reset \
&& ufw default deny incoming \
&& ufw default allow outgoing \
&& ufw allow 22/tcp \
&& ufw allow 80/tcp \
&& ufw allow 443/tcp \
&& ufw allow 8001/tcp
Now, if you need to add any other ports, now’s the time to go ahead and add them. If nothing more needs to be added, we can then run
ufw enable
When prompted to confirm, type y, hit enter, and ufw is active once again.
The benefit to the above is outgoing connections are always allowed, though only the ports you define are permitted to connect (i.e. incoming).