How to separate traffic by domain?

Background

I currently have several low power servers running on my local network. They all perform different services, but some of them are similar. I also own 3 domains and have many subdomains for these domains.

So what is your problem?

Well, as I said, some of my services are REALLY similar, and work on the same port (I have an Owncloud server on one, and my site is hosted on the other). This means that if I want my owncloud.mydomain.com to go to my Owncloud server and www.mydoamain.com to go to my web server, I have a bit of a problem. Both subdomains just go to my house, and the services use the same port. I cannot split traffic into a subdomain.

edit: it should also be able to redirect many types of traffic, such as SSH, HTTPS and FTP

Possible solutions

I have at least just starting another service on different ports, but not optimal AT ALL. This means that it’s weird to watch, it will be more difficult for people to use any of my services, and, as a rule, I will not feel good.

I thought of similar services on the same server, but some of them are pretty dinky servers. I would rather not do anything like that. Also, since the servers are a bit old, it's nice to know that if one of them dies, at least I will have other services. I do not think this option is good.

Best possible solution: I heard that there is a service with the exact functionality that I am looking for is called haproxy . My only problems with this is that I don’t know how to use this service, and I especially don’t know how to get from it I want.

My last question

I would like haproxy to work, I just need to know how to configure it the way I need. If someone has a link to a tutorial on how to do what I want specifically (I already learned how to make haproxy work, just not the way I want), then I would be very grateful. I would look for it myself, but I already have it, and I don’t even know what to look for. Can anyone help me out?

thanks

+4
source share
2 answers

Create your own configuration file, say haproxy.cfg, containing something like the following

defaults mode http frontend my_web_frontend bind 0.0.0.0:80 timeout client 86400000 acl is_owncloud hdr_end(host) -i owncloud.mydomain.com acl is_webserver hdr_end(host) -i www.mydomain.com use_backend owncloud if is_owncloud use_backend webserver if is_webserver backend owncloud balance source option forwardfor option httpclose timeout queue 500000 timeout server 500000 timeout connect 500000 server server1 10.0.0.25:5000 weight 1 maxconn 1024 check inter 10000 backend webserver balance source option forwardfor option httpclose timeout queue 500000 timeout server 500000 timeout connect 500000 server server1 10.0.0.30:80 weight 1 maxconn 1024 check inter 10000 

And then run haproxy on one of your servers.

 ./haproxy -f ~/haproxy.cfg 

Route all your domains and subdomains to this computer. They will be routed according to the configuration.

+5
source

You only need one IP address, but you need to configure the virtual host correctly. This link provides step-by-step configuration information for the Ubuntu virtual host. This is the easiest way, and everyone else will agree to this cheapest if you insist on using your personal network.

https://www.digitalocean.com/community/articles/how-to-set-up-nginx-virtual-hosts-server-blocks-on-ubuntu-12-04-lts--3

0
source

Source: https://habr.com/ru/post/1501227/


All Articles