You are not logged in.

#1 2013-12-22 20:40:12

mhelvens
Member
From: Leiden, the Netherlands
Registered: 2013-12-04
Posts: 69
Website

[SOLVED] Routing http requests based on domain-name

Hi all,

I'm running an Arch VPS, and I'd like to run multiple web services on it, each reachable through port 80 from a different domain-name. This would help me set up small experimental web-services without the need for additional IP-addresses. But I'm not sure how to accomplish this yet. I think I need to do something like this:

  • Set up each service from a different user, each listening to a different port (e.g., 10080, 20080, 30080, …)

  • Run a root process that listens to port 80 and redirects traffic to those ports based on the requested domain-name.

I'd like to know the easiest and most efficient way to set up this routing process. I'm sure I could rig something up, but I'm equally sure there must be a standard solution and a set of best practices. My Google-fu fails me.

Thanks in advance!

Last edited by mhelvens (2013-12-23 22:04:09)

Offline

#2 2013-12-22 22:06:33

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,231
Website

Re: [SOLVED] Routing http requests based on domain-name

What you're talking about is called Virtual Hosts. There are thousands of tutorials available to achieve this, including our own wiki: https://wiki.archlinux.org/index.php/LAMP#Virtual_Hosts

EDIT: And planning to run the HTTP daemon as root is defintely unnecessary

Last edited by fukawi2 (2013-12-22 22:07:27)

Offline

#3 2013-12-22 22:18:51

mhelvens
Member
From: Leiden, the Netherlands
Registered: 2013-12-04
Posts: 69
Website

Re: [SOLVED] Routing http requests based on domain-name

fukawi2 wrote:

What you're talking about is called Virtual Hosts.

Great! That's the search term I was looking for. :-)

EDIT: And planning to run the HTTP daemon as root is defintely unnecessary

I was under the impression that only root could listen on ports below 1024. What is the proper way to get around this? I would indeed prefer not to use root. :-)

Thanks!

Offline

#4 2013-12-22 22:30:18

progandy
Member
Registered: 2012-05-17
Posts: 5,280

Re: [SOLVED] Routing http requests based on domain-name

mhelvens wrote:

I was under the impression that only root could listen on ports below 1024. What is the proper way to get around this? I would indeed prefer not to use root. :-)

One way is for the server to starts as root, open the port and drop privileges. The alternative is to setcap CAP_NET_BIND_SERVICE for your server binary.
apache should be configured to drop capabilities by default. I believe nginx and lighttpd do the same.

PS: nginx calls vhosts "Server Blocks" and not Virtual Hosts like apache, lighttpd simply has "Conditionals" you can use for any sort of settings.
PPS: If you need to forward the request to a server on another port, apache has mod_proxy. You might be able to use fcgi, too.

Last edited by progandy (2013-12-22 22:39:06)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#5 2013-12-22 23:13:05

mhelvens
Member
From: Leiden, the Netherlands
Registered: 2013-12-04
Posts: 69
Website

Re: [SOLVED] Routing http requests based on domain-name

A quick Google search tells me CAP_NET_BIND_SERVICE doesn't work for individual scripts; just for binaries. All my web-apps (so far) are Node apps, and setcapping the node binary seems wrong.

I just realized I could use iptables to redirect port 80 to some higher port, then do the host-based routing from that other port. Any reason that's a bad idea (other than the latency created from two redirections)?

Last edited by mhelvens (2013-12-22 23:13:23)

Offline

#6 2013-12-23 01:50:10

progandy
Member
Registered: 2012-05-17
Posts: 5,280

Re: [SOLVED] Routing http requests based on domain-name

You could do that. If you want to run everything in node.js, then use bouncy to redirect to other ports.


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#7 2013-12-23 22:03:51

mhelvens
Member
From: Leiden, the Netherlands
Registered: 2013-12-04
Posts: 69
Website

Re: [SOLVED] Routing http requests based on domain-name

progandy wrote:

You could do that. If you want to run everything in node.js, then use bouncy to redirect to other ports.

I indeed ended up going that way. It's working well. Thanks all!

Offline

Board footer

Powered by FluxBB