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).
- On the local host, SSH to the remote host:
$ ssh -v -L 9000:localhost:8000 firstname.lastname@example.org
- On the remote host, run the Django dev server:
email@example.com:/path/to/my/django/project$ python manage.py runserver 0.0.0.0:8000
- On the local host, go to http://localhost:9000 in the browser
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.
Using LocalForward in your ~/.ssh/config
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
- How to expose a Flask local development server to the public using SSH remote port forwarding — posted 2013-02-12
- Notes on debugging ssh connection problems — posted 2011-08-31
- Fabric post-run processing Python decorator — posted 2010-11-06
- Class-based Fabric scripts via a Python metaprogramming hack — posted 2010-09-23
- Notes on sshfs on Ubuntu — posted 2010-04-05
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!