Here is how to run a Flask local development server on your local machine and expose it to the public via a remote server you have control over. This uses SSH remote port forwarding which is a converse of local port forwarding described here: 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
- On the remote host, edit the sshd_config file (mine was located at /etc/ssh/sshd_config) to allow remote hosts to connect to ports forwarded for the client:
- On the remote host, restart the SSH server:
$ sudo service sshd restart
- On the local host, SSH to the remote host:
$ ssh -v -R 50051:localhost:5000 email@example.com
- On the local host, run the Flask dev server:
$ python runserver.py localhost 5000
- Go to http://my.remotehost.com:50051 in the browser
Using RemoteForward in your ~/.ssh/config
You can also achieve the same results by using the
RemoteForward in your
Host myremote User eliot HostName my.remotehost.com RemoteForward 50051 localhost:5000
localtunnel by Jeff Lindsay exposes your local development server without requiring a public remote server.
- 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 — posted 2012-10-23
- 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
There are a bunch of good services that will do this more easily as well: http://john-sheehan.com/blog/a-survey-of-the-localhost-proxying-landscape
John, thanks for the great list. I'll remember that for the future. At the time I needed this, I actually was trying to expose my dev server at a specific URL that a third server was pointing at. I know my post fails to mention that.
Really helpful. Thanks.