Skip to content

How to redirect port 80 and 443 to Jupyter port 54321

Insert these command to iptable to redirect port 80 and 443 to 54321

iptables-save > iptables_Before_Add-54321
#iptables-restore < iptables_Before_Add-54321
sudo iptables -t nat -I PREROUTING -p tcp --dport 443 -j REDIRECT --to-ports 54321
sudo iptables -t nat -I OUTPUT -p tcp --dport 443 -o lo -j REDIRECT --to-port 54321
sudo iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 54321
sudo iptables -t nat -I OUTPUT -p tcp --dport 80 -o lo -j REDIRECT --to-port 54321
iptables-save > iptables_After_Add-54321 
#iptables-restore < iptables_After_Add-54321 

Delete above iptable rule

sudo iptables -t nat -D PREROUTING -p tcp --dport 443 -j REDIRECT --to-ports 54321
sudo iptables -t nat -D OUTPUT -p tcp --dport 443 -o lo -j REDIRECT --to-port 54321
sudo iptables -t nat -D PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 54321
sudo iptables -t nat -D OUTPUT -p tcp --dport 80 -o lo -j REDIRECT --to-port 54321
cat /etc/rc.local 
#!/usr/bin/env bash

sudo iptables -t nat -I PREROUTING -p tcp --dport 443 -j REDIRECT --to-ports 54321
sudo iptables -t nat -I OUTPUT -p tcp --dport 443 -o lo -j REDIRECT --to-port 54321
sudo iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 54321
sudo iptables -t nat -I OUTPUT -p tcp --dport 80 -o lo -j REDIRECT --to-port 54321

su -c "/usr/bin/lab &" winuthayanonlab

exit 0
chmod 755 /etc/rc.local
systemctl status rc-local
systemctl restart rc-local
systemctl status rc-local

https://wiki.jenkins.io/display/JENKINS/Running+Jenkins+on+Port+80+or+443+using+iptables

https://serverfault.com/questions/540241/iptables-how-to-redirect-all-8443-incoming-and-outgoing-to-443

https://jupyterhub.readthedocs.io/en/stable/reference/config-proxy.html

https://hands-on.cloud/how-to-setup-jupyter-behind-nginx-proxy/

Published inUncategorized

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *