Showcase websites from your local machine easily
We want to make yourdomain.com (could be subdomain like showcase.yourdomain.com as well, of course) open whatever webapp (Rails, Sinatra etc.) is running on port 3000 on your development machine.
Create ~/bin/ssh_forward with this contents:
#!/usr/bin/env bash
domain=yourdomain.com
echo "http://$domain" | pbcopy
python -mwebbrowser http://$domain &
ssh -nNT -v -R0.0.0.0:8888:localhost:3000 $domain
On the server add this nginx site configuration:
server {
server_name yourdomain.com;
location / {
proxy_pass http://localhost:8888;
error_page 502 /502.html;
}
location = /502.html {
root /var/www/yourdomain;
}
}
As you can see we want to include a nice notification when either your local machine is not serving anything on port 3000 or ssh forwarding is not running.
Note: /var/www/yourdomain/502.html must have absolute references to images and other resources.
To enable ssh forwarding on the server you also have to add this line:
GatewayPorts yes
to /etc/ssh/sshd_config and restart ssh service:
$ sudo /etc/init.d/ssh restart
Usage:
Make sure your development server is serving the app:
$ puma -p 3000
Then run ssh_forward and others should be able to access your local server from yourdomain.com.
If the setup is not working properly make sure that maybe firewall on the server is not interfering.
That's it, enjoy!