In the modern world of web development you will need to consume automatic external calls to your application at some point. These calls will trigger some sort of action in your application and are usually called webhooks. It is very hard to debug these, since you cant really point webhooks to your local development environment. To overcome this we will use SSH tunnel to direct traffic to our local development server.
This example is using Django web framework but you really can adapt it to any language or framework. This approach was tested on Ubuntu server with local Django project setup on OS X.
Install SSL devserver
Firstly we will need to install sslserver since the default Django development server does not support SSL. The django-sslserver is a great fit and you can install it easily using pip:
pip install django-sslserver
Add to installed apps:
INSTALLED_APPS += ( 'sslserver', )
Configure remote server
We will need to enable the GatewayPorts in our SSH config. This setting specifies whether remote hosts are allowed to connect to ports forwarded for the client. You can update your /etc/ssh/sshd_config and enable it:
Open port on remote server:
ufw allow 5000
I am using ufw in this example, but you can really use any firewall (you are using firewall right?).
Run local SSL dev server
Run devserver with local copy of example.com certfificates on port 8000:
python manage.py runsslserver --key server.key --certificate server.crt --addrport 127.0.0.1:8000
Create SSH tunnel
Create SSH tunnel to forward all connections from remote host on port 5000 to local port 8000:
ssh -v -R 5000:localhost:8000 firstname.lastname@example.org -p 1234
Now every request that points to https://example.com:5000/ will be forwarded to our local development server that is running on port 8000.