Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PagePark routing requests between apps on the same server #17

Closed
scripting opened this issue Feb 4, 2021 · 5 comments
Closed

PagePark routing requests between apps on the same server #17

scripting opened this issue Feb 4, 2021 · 5 comments

Comments

@scripting
Copy link
Owner

scripting commented Feb 4, 2021

The problem

Longstanding problem with PagePark, my homebrew web server.

  • Suppose two apps are running on the same machine where PP is the http server.

  • Say one app is on the domain hello.com and the other is goodbye.com.

  • Suppose the first makes a request of the second.

    http://goodbye.com/index.html

  • It will get a connection refused.

  • Make the request from another server and it works fine.

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
Copy link

tamaker commented Feb 4, 2021

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
Copy link

mcenirm commented Feb 5, 2021

I think this is related to scripting/Scripting-News#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
Copy link

scotthansonde commented Feb 5, 2021

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
Copy link
Owner Author

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

I posted this note in my development diary.

image

@scripting
Copy link
Owner Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants