Here is how to run a Django local development server on a remote machine and access it in your browser on your local machine using SSH port forwarding. (This is useful if there is a firewall blocking access to the port of your Django local dev server (port 8000).
$ ssh -v -L 9000:localhost:8000 email@example.com
firstname.lastname@example.org:/path/to/my/django/project$ python manage.py runserver 0.0.0.0:8000
Note: The local port and the remote port can be the same (i.e. you can use 8000 instead of 9000). I just made them different to show which port is which.
You can also achieve the same results by using the
LocalForward in your
Host myremote User eliot HostName my.remotehost.com LocalForward 9000 localhost:8000
The cool thing about the config file is that you don't have to resort to using a .ssh/config. You can place the desired configs in any file then pass the -F configfile flag. I use this with -v and make a term window dedicated to the tunnels then I can see some info showing me that it's working properly.
In that config file you can create multiple directives. This is a really awesome way to forward lots of ports over a single ssh connection.
I dig your blog. Cheers!
Very helpful, thanks!
I'm Eliot and this is my notepad for programming topics such as Python, Django, Ubuntu, Emacs, etc... more »