Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
em-proxy proxy.rb.erb
# proxy.rb.erb
require 'em-proxy'
# @emproxy_port - the port we want this process receiving traffic on (ex: 8080)
# @nginx_port - the port that normally processes traffic that we are now duplexing (ex: 81)
# @proxy_ip - the IP address we are duplexing to (ex: 10.10.10.10)
# @proxy_port - the port that we are duplexing to (ex: 80)
Proxy.start(:host => "0.0.0.0", :port => <%= @emproxy_port %>) do |conn|
conn.server :self, :host => '127.0.0.1', :port => <%= @nginx_port %>
conn.server :proxy, :host => '<%= @proxy_ip %>', :port => <%= @proxy_port %>
conn.on_data do |data|
data
end
conn.on_response do |server, resp|
resp if server == :self
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment