Apache, grouping subdomains - apache2

I'm trying to set up some basic virtualhosts in Apache2, within the domain
nosoftpatents.com (invented). I'm supposed to have two subdomains, friendly
and previous, each of them accessible from two ports, 80 and 8800, that are to
be linked to the stable and devel subdirectories of each domain. So far, I
have this:
<VirtualHost *:80>
ServerName friendly.nosoftpatents.com
DocumentRoot /var/www/nopatents/friendly/stable
</VirtualHost>
<VirtualHost *:80>
ServerName previous.nosoftpatents.com
DocumentRoot /var/www/nopatents/previous/stable
</VirtualHost>
<VirtualHost *:8800>
ServerName friendly.nosoftpatents.com
DocumentRoot /var/www/nopatents/friendly/devel
</VirtualHost>
<VirtualHost *:8800>
ServerName previous.nosoftpatents.com
DocumentRoot /var/www/nopatents/previous/devel
</VirtualHost>
Is there a more elegant way of doing it? Some way of grouping the hosts from the
same port?

Related

Apache 2 different Virtual Hosts point to first one

Well, I'm pretty new to this, so, I'm sorry if I'm making some stupid mistake but I've been trying to make my Apache Virtual Hosts work fine for different domains. I have one VPS with CentOS 6 and Apache 2 where I'm running 2 websites with diffent domain names; they were both working fine some days ago. But After I made some changes (i dont remember them) they're acting stupidly. The problem is that the both of the domains are pointing to the first document root in the vhosts file. This is my vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin support#domain.me
DocumentRoot /var/www/domainme
ServerName domain.me
ErrorLog /var/www/log/domainme.log
</VirtualHost>
<VirtualHost *:80>
ServerAdmin support#domain.com
DocumentRoot /var/www/domaincom
ServerName domain.com
ErrorLog /var/www/log/domaincom.log
</VirtualHost>
Everytime I try to access domain.com it gives me the index file of domain.me but if I put domain.com's configuration before the domain.me in vhosts file, and go to domain.me; it will give me the index of domain.com. I have two IP's for the VPS by the way.
Thank for reading, hope that its not a big issue.
Try this one
Listen *:80
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin contact#domain.tld
DocumentRoot /path/to/domain1/
ServerName domain1.com
ServerAlias domain1.com www.domain1.com
</VirtualHost>
<VirtualHost *:80>
ServerAdmin contact#domain.tld
DocumentRoot /path/to/domain2/
ServerName domain2.com
ServerAlias domain2.com www.domain2.com
</VirtualHost>

Apache2 isolate virtualhosts

I'd like to isolate each "www subdirectory" so mysite1.ext can't access to mysite2.ext files, is this possible? How can I do it?
you Must conf You virtualHost Apache for this
like This
<VirtualHost x.x.x.x:80>
ServeName www.example.com
DocumentRoot /path/to/your/virtualroot
...
... usual stuff ...
...
php_admin_value open_basedir /path/to/your/virtualroot:/some/other/path
</VirtualHost>
Last Line Is For Isolate PHP To Access Other Directory
To do what you want in Apache you would use Name Based VirtualHosts. This allows you to configure two or more separate Web server environments on one IP address. It would look something like this.
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.mysite1.ext
ServerAlias domain.ext *.domain.ext
DocumentRoot /www/domain
</VirtualHost>
<VirtualHost *:80>
ServerName www.mysite2.ext
DocumentRoot /www/otherdomain
</VirtualHost>
You can read more about this configuration here This would all go in Sites.enabled or http.conf depending on your end stage configuration.

Configure one virtual host handling specific subdomain (or directory) and another virtual host catching all others

I want to configure a VirtualHost for subdomain.mydomain.tld with own DocumentRoot.
and another VitualHost with own DocumentRoot catching all others.
I tried
<VirtualHost *:80>
ServerAlias subdomain.mydomain.tld
...
</VirtualHost >
<VirtualHost *:80>
ServerAlias *.mydomain.tld mydomain.tld
...
</VirtualHost >
and it diddn't work properly...
any other suggestions?
If there is no way to fix this, i would like to map a virtulahost to a subfolder of mydomain.tld and let the other VirtualHost handle the rest, but no clue how to do this.
Thanks in advance.
If you don't specify a ServerName apache can get a bit confused about which vhost should be used to serve a request.
Try poping in ServerName in as below
<VirtualHost *:80>
ServerName subdomain.mydomain.tld
...
</VirtualHost >
<VirtualHost *:80>
ServerName mydomain.tld
ServerAlias *.mydomain.tld
...
</VirtualHost >

Multiple hostnames, same domain, different virtualhost

I am trying to route requests to different docroots depending on the HOST name (not domain name):
<VirtualHost 123.123.12.12:80>
SuexecUserGroup "#521" "#521"
ServerName forum.somesite.net
DocumentRoot /home/somesite/public_html/forums
</VirtualHost>
<VirtualHost 123.123.12.12:80>
SuexecUserGroup "#521" "#521"
ServerName www.somesite.net
DocumentRoot /home/somesite/public_html
</VirtualHost>
It is not working though. Apache seems to go to the first entry regardless of what is in the hostname. What am I doing wrong?
Try changing the second Virtual host to this
<VirtualHost 123.123.12.12:80>
SuexecUserGroup "#521" "#521"
ServerName somesite.net
ServerAlias www.somesite.net
DocumentRoot /home/somesite/public_html
</VirtualHost>

What Virtual Host Definitions do I need to support subdomain.mydomain.com and *.mydomain.com on the same IP Address on Apache 2?

I have a virtual host setup on Apache 2 like so (simplified):
<VirtualHost *>
ServerName domain.com
ServerAlias *.domain.com
DocumentRoot /var/www/domain.com/html
</VirtualHost>
<VirtualHost sub1.domain.com>
ServerName sub1.domain.com
DocumentRoot /var/www/sub1.domain.com/html
</VirtualHost>
<VirtualHost sub2.domain.com>
ServerName sub2.domain.com
DocumentRoot /var/www/sub2.domain.com/html
</VirtualHost>
The outcome I'm looking for is everything that isn't sub2.domain.com or sub1.domain.com should go to the domain.com. They all have to be on the same default port and they all share the same IP address.
What actually happens is that sub2 goes to sub2 as expected, and everything else goes to sub1, i.e. the wildcard definition is ignored.
How can I fix this up?
Thanks!
Change the <VirtualHost sub1.domain.com> to <VirtualHost *> and
<VirtualHost sub2.domain.com> to <VirtualHost *> also. First one is the default one anyway.

Resources