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 eliot@my.remotehost.com
- On the remote host, run the Django dev server:
eliot@my.remotehost.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 ~/.ssh/config
file:
Host myremote User eliot HostName my.remotehost.com LocalForward 9000 localhost:8000