Multiple web servers sharing a public IP - apache

I have two entries in my DNS: www.domain.tld and svn.domain.tld
Both point to my company's public IP address of 88.77.66.55.
I have two apache servers serving port 80 on my LAN behind that public IP. One hosts my website on 192.168.1.2 and the other hosts my SVN server at 192.168.1.3.
I would like to route the IPs to:
www.domain.tld -> 192.168.1.2
svn.domain.tld -> 192.168.1.3
Here's my current intended design, but I don't know if it's feasible so I'm looking for feedback. My router will forward all port 80 data to 192.168.1.2. Then, on that machine:
/etc/apache2/httpd.conf
---
NameVirtualHost 192.168.1.2:80
NameVirtualHost 192.168.1.3:80
<VirtualHost 192.168.1.2:80>
ServerName www.domain.tld
</VirtualHost>
<VirtualHost 192.168.1.3:80>
ServerName svn.domain.tld
</VirtualHost>
Am I using the correct mechanism to accomplish this? Can I use hostnames instead of IPs? I'd like to get some indication of issues before I start messing with configurations and cause downtime.

I think that will work. Nginx reverse proxy is another way to do this on a larger scale.

Related

Apache different sites on different ports, still links to same site. Bind9 for domain names

I've been trying to create 3 different domains linking to 3 different sites on the same machine, 2 which works but the third on the different port links to the first page.
My apache config looks like this:
Listen 81
NameVirtualHost *:81
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /var/www/www
</VirtualHost>
<VirtualHost *:80>
ServerName www2.example.com
DocumentRoot /var/www/www2
</VirtualHost>
<VirtualHost *:81>
ServerName controlpanel.example.com
DocumentRoot /var/www/controlpanel
</VirtualHost>
I've used Bind9 to set up the domains.
www IN A 123.123.123.123
www2 IN A 123.123.123.123
controlpanel IN A 123.123.123.123
www and www2 works fine and shows the correct site, however controlpanel.example.com also links to the first www site. When I enter the port manualy on the ip, xxx.xxx.xxx.xxx:81, i get linked correctly. The thing is that I don't really know where I'm doing it wrong, this is the first time I'm trying anything like this. You got any ideas?
Im also running this on an old ubuntu 12.04 server.
Regarding where you're going in the comments for the previous answer:
You could add a port 80 virtualhost for controlpanel.example.com and put a single statement inside,
Redirect / http://controlpanel.example.com:81
The purpose of the ServerName is not to inform the browser what port your webserver is using. It's used for name-based virtualhosts and as a last resort for self-referential links (out of the box, self-referential links are generated with whatever the client already thought it was accessing via the Host: header)
But there is definitely something quite bizarre about your requirement. Usually the motivation is to not use custom ports, and if they are, to address the server with a low port and have the por remapped by some intermediary (load balancer, proxy).
If you want your third virtualhost to be simulataneously the defautl on port 81 and a name-based option on port 80:
Change
<VirtualHost *:81>
to
<VirtualHost *:80 *:81>
Apache finds the set of virtual hosts with the best IP:PORT based match first, then if NameVirtualHost also matches, starts looking at the ServerNames from that set.

Apache reverse proxy, one server, multiple domains

I am trying to manage 2 domains with one server (running proxmox with several CT), I am using reverse proxy but seems to be wrong.. here's my configuration:
Let's say we have the main server running proxmox where I managed IPTables to redirect port 80 to the port 80 of my first container (CT01) and port 8109 to port 80 of my second container (CT02).
While using the port in my browser, everything is working well, and I am able to reach each container.
I bought 2 domain names, one for my private server (CT01) and another one for a business server (CT02). I associated both of the domain to my server address, and while typing one or another of them I am redirected to CT01 (normal, browser is running the address to the default port).
So now I tried to use reverse proxy in order to redirect to the desired server (DomainA -> CT01, DomainB -> CT02), I created 2 files in /var/apache2/sites-available/ :
/var/apache2/sites-available/domainA.com:
<VirtualHost *:80>
ServerName domainA.com
DocumentRoot /var/www/
</VirtualHost>
/var/apache2/sites-available/domainB.com:
<VirtualHost *:80>
ServerName domainB.com
ProxyPreserveHost On
ProxyRequests On
ProxyPass / http://x.y.z.h:8109/
ProxyPassReverse / http://x.y.z.h:8109/
<Location />
Order allow,deny
Allow from all
</Location>
</VirtualHost>
Then I runned a2ensite domainA.com and a2ensite domainB.com. I restarted my apache service.
But nothing have changed: both my domainA and domainB redirect me to the same container (CT01).
Any idea?
What i may suggest is doing a new CT just to host a proxy (nginx for example) that will route the requests to one or the other site depending of the Host: field value of the HTTP request. This may be a little bit overkill if it's just for two sites, but when you want to have more, it can be very useful. Plus the NGinx can be used to cache, etc.
Let me know if you are interested. I know a tutorial that you may follow, but it's in french : http://blog.ganbaranai.fr/2013/08/il-etait-une-fois-proxmox-derriere-une-ip-unique/
Hope it helps.
Regards,

apache httpd name-based virtual host: use ip or domain name?

In Apache web server, when using name-based virtual hosting you can use either the IP or the actual domain name in the VirtualHost directive.
(Name-based virtual hosting on Debian is enabled via /etc/apache/ports.conf through NameVirtualHost <ip>:<port> statement, where <port> has to be the same one as in a Listen directive.)
So, then this:
<VirtualHost 10.0.0.1:80>
...
or this:
<VirtualHost sub.domain.tld:80>
...
will equally work.
What are the differences, and which approach should be preferred?
Using an IP address is preferred so that your config can be parsed even if DNS resolution fails.
You can use the ServerName directive to control which hostname the VirtualHost block applies to, without triggering a DNS resolution:
<VirtualHost 10.0.0.1:80>
ServerName sub.domain.tld
...
</VirtualHost>
http://httpd.apache.org/docs/current/dns-caveats.html has more examples of good and bad practice.

Multiple Apache2 vhosts are pointing to the same website

I'm running Apache2 on Ubuntu 10, and I have my site configuration files laid out numerically and in order. My default server is psychedeli.ca, but I also run another site off the same box at mahoganytales.com. Currently, both of these domains point to the same site (the one for psychedeli.ca). The declaration NameVirtualHost *:80 is in my ports.conf file, so I'm pretty sure my global server config checks out. How can I fix this?
Here are my vhost files:
001-psycho
<VirtualHost *:80>
DocumentRoot /var/apps/psycho/public
ServerName psychedeli.ca
</VirtualHost>
002-mahogany
<VirtualHost *:80>
DocumentRoot /var/apps/mahogany/public
ServerName mahoganytales.com
</VirtualHost>
try create new conf file at /etc/apache2/conf.d, e.g., vhosts.conf
with this content in it:
NameVirtualHost *
It looks like the default configuration is in effect rather than your host entries. Following is the procedure that works in Ubuntu Apache2.
First,
create a VirtualHost in /etc/apache2/sites-available/somesite,
then a2ensite somesite to make it live.
Finally, /etc/init.d/apache2 restart to restart apache.
If you think, you have followed the above steps, then can you please confirm, that you have your hosts files in /etc/apache2/sites-enabled/?
Each domain name needs to have it's own single unique ip address, that's how different sites are found.
By using the *:80 in the virtual host directive, you're instructing Apache to listen on all IP addresses, port 80 and send it to this directory. With your second vhost, you're doing the same thing (All IP's port 80, and send it there). Well, since you're giving it two conflicting statements, it takes the first match, and uses it.
If you want to serve multiple websites, each must answer to it's own unique IP address, ie:
site aaa.com - 145.25.82.110
site bbb.com - 145.25.82.111
From there, each vhost entry will listen on it's own ip address and port for each site. In the OP's case the vhost needs to change to (using the example IPs):
&ltVirtualHost 145.25.82.110:80>
DocumentRoot /var/apps/psycho/public
ServerName psychedeli.ca
&lt/VirtualHost>
&ltVirtualHost 145.25.82.111:80>
DocumentRoot /var/apps/mahogany/public
ServerName mahoganytales.com
&lt/VirtualHost>
This instructs the server to listen on static IP 1 port 80 (as defined in the named.conf and associtated bind config files, and send it to the first site base directory, and any calls on the second static IP port 80 and send it to the second site base directory.
As for configuring bind/named, that's beyond the scope of this question...

IP based VirtualHost and Apache

I have this webserver that have an IP address xxx.xxx.xx.x, I also have a website I want to publish, but I do not have any domain for my website yet.
So in my httpd-vhosts.conf file I have this setting:
<VirtualHost xxx.xxx.xx.x>
ServerName xxx.xxx.xx.x
DocumentRoot "C:\Sites\mysite"
</VirtualHost>
And since I dont have a domain I really want to use the IP address to reach my site, but I have tried this and it does not work. I guess you HAVE to set a server name in ServerName as the title says.
Are there any ways for me to make my website public through my IP address, if yes how can I do this?
Try
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot C:\Sites\mysite
ServerName xx.xx.xx.xx
</VirtualHost>
Remember to restart apache,
You may also need to add,
Listen xx.xx.xx.xx:80
If you only have the one website on this server, you don't need a virtual host. Just set the DocumentRoot correctly and away you go. Also make sure Apache is listening on all IP addresses (Listen 0.0.0.0:80.)
If that doesn't work for you, from your command prompt do:
telnet xx.xx.xx.xx 80
GET /
and see what you get back - you should get your website's default page.
This is not a programming question.
But anyway,
Set the VirtualHost to * rather than a specific IP address. I don't think you need the servername either then.