Routing problems, can't get a simple proxy to work without any rules even
freed00m opened this issue · 8 comments
Greetings
I am very interested about using toxy but I ran into usage issues right from the start.
I cannot seems to get a correct response from a multiple servers, cause some direct IP access and many many sites are refusing to forward, I have tried it at multiple AP home/work/cafferooms etc
I run proxy like this
~$ node name.js
var toxy = require('toxy')
var poisons = toxy.poisons
var rules = toxy.rules
// Create a new toxy proxy
var proxy = toxy()
// Default server to forward incoming traffic
proxy
.all('/*')
.forward('http://4chan.org/')
proxy.listen(3000)
console.log('Server listening on port:', 3000)
And 4chan kindly responds with Direct "IP access not allowed"
I have no firewall set on my debian machine.
more demos: https://youtu.be/dvarUf868S8
Thank you for the time.
Your trouble is due to the Host
header of the target URL server is not forwarded by default by toxy
.
You must explicitly enable this. There're multiple way to do that:
Via forwardHost
option param:
var toxy = require('.')
var poisons = toxy.poisons
var rules = toxy.rules
// Create a new toxy proxy with custom options
var proxy = toxy({ forwardHost: true })
proxy
.all('/*')
.forward('http://4chan.org')
proxy.listen(3000)
console.log('Server listening on port:', 3000)
Via host built-in middleware (inherited by rocky):
var toxy = require('.')
var poisons = toxy.poisons
var rules = toxy.rules
// Create a new toxy proxy
var proxy = toxy()
proxy
.all('/*')
// Define a specific Host header
.host('4chan.org')
.forward('http://4chan.org')
proxy.listen(3000)
console.log('Server listening on port:', 3000)
Using a custom middleware:
var toxy = require('.')
var poisons = toxy.poisons
var rules = toxy.rules
// Create a new toxy proxy
var proxy = toxy()
proxy
.all('/*')
.use(function (req, res, next) {
req.headers.host = '4chan.org'
next()
})
.forward('http://4chan.org')
proxy.listen(3000)
console.log('Server listening on port:', 3000)
BTW I've discovered a minor issue in rocky
regarding to the Host
header forward logic, so please update toxy
to avoid troubles:
npm install toxy --force
I will test later this day :) using vpn for now :) thank you very much
I can confirm the second and the third option worked as advertised :))
I have updated toxy with --force as you mentioned and the parameter
var proxy = toxy({ forwardHost: true })
did not help if it should have the same functionality as with middleware then it is a bug, if the mechanics differs then you investigate and decide about closing this issue.
Anyway thank you very much :)
With forwardHost
the behavior is sightly different.
If using that option, the Host
header will be automatically extracted from the target server URL, for instance, if you're forwarding to http://4chan.org
, then the host value will be: 4chan.org
.
I've tested it in multiple scenarios and it should work properly.
To which server URL are you forwarding? That might help me to do a better diagnostic.
server is "doontpanic.com" it sits behind NGINX and perhaps it won't let you extract the host.
var toxy = require('toxy')
var poisons = toxy.poisons
var rules = toxy.rules
// Create a new toxy proxy with custom options
var proxy = toxy({ forwardHost: true })
proxy
.all('/*')
.forward('http://doontpanic.com')
proxy.listen(3000)
console.log('Server listening on port:', 3000)
Hmmmm :| then it must some networking mamboo jumboo, anyway middleware works so I am happy.
About the videos, I am used to do it, cause often nobody understands what I want to say, or I am explaining it completely retardly.
No worries, however be sure you've updated toxy
and its dependencies (actually only rocky
is required).
I'm going to close this for now. Thank you for reporting.