scripting / pagePark

I wrote this simple Node.js folder-based HTTP server that serves static and dynamic pages for domains I've bought but not yet used. Then I kept going...
http://pagepark.io/
MIT License
138 stars 19 forks source link

PagePark routing requests between apps on the same server #17

Closed scripting closed 3 years ago

scripting commented 3 years ago

The problem

Longstanding problem with PagePark, my homebrew web server.

Where to look

This is where PP maps requests to domains it's serving.

BTW, it uses request, yes I know it has been deprecated.

The pipe stuff in delegateRequest is like a black box to me, I don't really understand the magic it's doing or if it's really necessary. It probably isn't, but I wrote this code a long time ago, when I wasn't as skilled in Node.

Any help much appreciated. :-)

tamaker commented 3 years ago

Please disregard if this is off base, not considering all the details you've shared or is something so basic that you've already ruled it out...

The host machine may need to have ports 1339 and 1340 open (on my Ubuntu dev server, for example, for Node.js development, when I'm ready to test from another machine on my network, I have to use UFW to specifically OPEN the custom ports I'm using.

And I think I saw a reference to port 80 in the code as well, so nothing else can be running on that port also.

That would be my starting point at least. Next I would look to see if I can identify any networking related issues that may come into play -- same ip range? same VLAN?

Good luck!

mcenirm commented 3 years ago

I think this is related to https://github.com/scripting/Scripting-News/issues/110 where the PREROUTING to map 80 to the pagepark listener is never even seen by connections that originate from the same host. That is, processes on that server try to connect to port 80, and get blocked because nothing is listening there. You can diagnose this by opening a terminal and using sudo nc -k -l -v 80 < /dev/null to see what clients connects to port 80 locally, and then trying the relevant cross-site requests.

Update: https://grainier.net/iptables-nat-prerouting-not-work-localhost/ has a reasonably concise explanation of the PREROUTING issue with localhost:

This happens because PREROUTING isn’t used by the loopback interface. Therefore, you have to add an OUTPUT rule along with the PREROUTING rule.

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 9191
iptables -t nat -A OUTPUT -p tcp -o lo --dport 80 -j REDIRECT --to-ports 9191

(You'd need to replace "9191" with the actual listener port in both entries.)

scotthansonde commented 3 years ago

I was about to point to a ServerFault entry about OUTPUT rules for localhost, but @mcenirm beat me by 30 seconds. 😄 Here it is anyway: https://serverfault.com/questions/211536/iptables-port-redirect-not-working-for-localhost

scripting commented 3 years ago

Thanks to all esp @mcenirm. That was the problem. Whew. Glad I asked.

I posted this note in my development diary.

image

scripting commented 3 years ago

Updated the docs.

https://github.com/scripting/pagePark#mapping-port-80-to-1339