How Can We Help?
To have a concrete example, let’s say you want to forward requests going to 80 to a server listening on port 8080.
Note that you will need to make sure port 8080 is allowed, otherwise ufw will block the requests that are redirected to 8080.
sudo ufw allow 8080/tcp
Add before filter section in /etc/ufw/before.rules(top of file):
*nat
:PREROUTING ACCEPT [0:0]
-A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
COMMIT
Then restart ufw.