Skip to content

Instantly share code, notes, and snippets.

@jc00ke
Forked from pogodan/tunnel.thor
Created August 23, 2011 21:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jc00ke/1166687 to your computer and use it in GitHub Desktop.
Save jc00ke/1166687 to your computer and use it in GitHub Desktop.
thor/pow reverse SSH tunnel
server {
listen [YOUR IP]:80;
server_name *.dev.jc00ke.com;
location / {
if ($host ~* "(.*)\.dev\.jc00ke\.com" ) {
set $tunnel_app $1.lvh.me;
}
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $tunnel_app;
proxy_redirect off;
proxy_pass http://localhost:17642;
}
}
# http://pogodan.com/blog/2011/05/03/reverse-ssh-tunnel-any-rack-app-with-pow-and-nginx
class Tunnel < Thor
method_options :environment => "development", :aliases => "-e", :desc => "Config environment"
desc "start", "Start an ssh tunnel"
def start
command = "ssh -nNT -g -R *:#{tunnel['public_port']}:0.0.0.0:#{tunnel['local_port']} #{tunnel['username']}@#{tunnel['public_host']}"
puts "executing #{command}"
exec command
end
private
def tunnel
@tunnel ||= YAML.load_file(File.expand_path('~/.tunnel.yml'))[options[:environment]]
end
end
development:
username: foo
public_host: some_server
public_port: 17986
local_port: 5000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment