Securely Sharing Your Development Environment
Warning
Be extra careful with this process! The end result will be that your development instance will be accessible to the internet. If you have simple logins and passwords like “admin/test.223” because you thought it was just your local dev instance and it doesn’t matter, now it matters! Whenever you’re not using the SSH tunnel for testing, shut it down so there’s no more remote access.
Never expose a development instance to the internet where you’ve replicated production data locally. Well, maybe not never, but with extreme care and intention.
Also not - if you only want to test with mobile devices that require a valid TLS certificate, do not use method. Instead, use nginx-local-ip
Overview
When using a local development environment, you may want to share your work with other collaborators. By using a publicly accessible web server, you can receive the secure https requests and forward them back to your CHT instance which doesn’t have https set up:
Once you have this web server set up, you may continue to use it whenever you want by simply reconnecting to it via the secure tunnel.
Prerequisites
This guide assumes:
- You have a local dev instance set up of cht-core
- You have the generic Medic app installed on your Android device. This version allows you to enter a custom CHT URL on first run.
- You have an Ubuntu >18.04 server with a public IP and a DNS entry that you can SSH into and have sudo on
- You have Apache >2.4.29 installed on the Ubuntu server and can add a new vhost to it, including an SSL cert. (nginx could be used instead as well, but not covered here)
- You have certbot installed from letsencrypt.org
The steps in this guide can be done on any of the cheap server providers out there (Digital Ocean has a $5/mo server).
Steps
Create a DNS entry. Let’s assume it’s
cht.domain.com
. It should point to the IP of your Ubuntu server. If you do not already have a domain name with DNS services that you can use, you can sign up for a free service to do this like noip.com.On your Ubuntu server, create a new apache vhost in
/etc/apache2/sites-available/100-cht.domain.com.conf
with the following contents:<VirtualHost *:80> ServerName cht.domain.com RewriteEngine on RewriteRule (.*) https://cht.domain.com%{REQUEST_URI} </VirtualHost> <IfModule mod_ssl.c> <VirtualHost *:443> ServerName cht.domain.com SSLEngine On <IfModule mod_headers.c> Header always set Strict-Transport-Security "max-age=63072000; preload" </IfModule> RewriteEngine on Include /etc/letsencrypt/options-ssl-apache.conf SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key ProxyPass / http://localhost:8081/ ProxyPassReverse / http://localhost:8081/ RequestHeader set X-Forwarded-Proto "https" </VirtualHost> </IfModule>
Enable the new site:
a2ensite 100-cht.domain.com
Restart apache and ensure there’s no errors:
apachectl restart
Create the TLS certificate:
certbot -d cht.domain.com
When prompted choose no redirect: “No redirect - Make no further changes to the webserver configuration.”
Restart apache and ensure there’s no errors:
apachectl restart
In a browser, test that you can connect to your server with no errors at https://cht.domain.com (you may get a
500
error, but you shouldn’t get any TLS errors)Ensure your cht-core local dev instance is running by going to http://localhost:5988/
On your local dev box, set up the SSH tunnel with:
ssh -NT -R 8081:127.0.0.1:5988 cht.domain.com
This assumes your local username is the same as it is on cht.domain.com. This command will hang and you may exit when down with
ctrl + c
In a browser, test again that you now see your local dev instance and it loads correctly at https://cht.domain.com
If needed, reset the Medic app on your phone so that it prompts which instance to use
In the app on your phone, choose “custom” for which instance to use and enter https://cht.domain.com. You should now see your local dev instance in the CHT Android device. Happy testing!
Tunnel command breakdown
From the SSH command in step 10 above:
8081
- Remote port on cht.domain.com to listen to. This is the same port that apache redirects to in step 2 above.127.0.0.1
- Host to send forwarded traffic to. In this case, your local machine.5988
- Local port where traffic from step one will be sent. In this case, your instance of the CHTcht.domain.com
- Public domain where you have an SSH account and we’ll attach port8081
to from step 1.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.