ruby - Connection refused when using Rack Proxy -
i'm trying catch *.dev
requests on port 80 , send them right rack project using rack proxy. i'm able catch requests , based on uri i'll config.ru
in specific folder. when i'm able find 1 i'll boot server on port 3000.
after that, whenever recieve request on port 80, try set http_host
localhost:3000
, i'm getting message unexpected error while processing request: connection refused - connect(2) "localhost" port 3000
. able access application through localhost:3000
, not through *.dev
domain. tried using different ports, that's not working either, guess has user that's running it. however, hope can me this.
require 'rack-proxy' class appproxy < rack::proxy def rewrite_env(env) request = rack::request.new(env) site = request.host[0..-5] uid = file.stat(__file__).uid path = etc.getpwuid(uid).dir + '/software/applications/' front_controller = "#{path}#{site}/config.ru" if file.file?(front_controller) system "rackup -p 3000 -d #{front_controller} " env["http_host"] = "localhost:3000" else raise exception.new "not found" end env end end run appproxy.new
edit: i've checked if there listening on port 3000. after running server , sudo lsof -i -n -p | grep tcp
following result ports 80 , 3000:
ruby 56247 root 10u ipv4 0x727d74bd0b95bd9b 0t0 tcp *:80 (listen) ruby 56247 root 11u ipv4 0x727d74bd0a3b9bfb 0t0 tcp 127.0.0.1:80->127.0.0.1:52773 (established) ruby 56255 root 12u ipv6 0x727d74bd094e3c8b 0t0 tcp [::1]:3000 (listen)
i'm not sure if useful because don't know exact meaning of this.
solved it. problem booting server bit slower setting http_host different location , port 3000 not in use yet. waiting second solved problem. code looks now:
require 'rack-proxy' class appproxy < rack::proxy def rewrite_env(env) request = rack::request.new(env) site = request.host[0..-5] uid = file.stat(__file__).uid path = etc.getpwuid(uid).dir + '/software/applications/' front_controller = "#{path}#{site}/config.ru" if file.file?(front_controller) system "rackup -d -p 3000 #{front_controller} " sleep(1) env["http_host"] = "localhost:3000" else raise exception.new "not found" end env end end run appproxy.new
Comments
Post a Comment