logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Unable to set subdomains in Apache 2.4
Author
cinciala



Joined: 22 Apr 2013
Posts: 5

PostPosted: Mon 22 Apr '13 14:59    Post subject: Unable to set subdomains in Apache 2.4 Reply with quote

I have spent literally hours trying to find a working solution for setting up a subdomain for my Apache server. Unfortunately nothing has worked for me, so I would like to ask for a help here.

Here is my setting:

(1) I have two virtual hosts defined in httpd-vhosts.conf: domain1.com and domain2.com. Included NameVirtualHost *:80 both into httpd-vhosts.conf and httpd.conf.

(2) Settings in httpd-vhosts.conf:
Quote:

# domain1.com virtual host.
ServerAdmin info@domain1.com
DocumentRoot "d:/Websites/domain1_com/www"
ServerName domain1.com:80
ServerAlias *.domain1.com
ErrorLog "d:/Websites/domain1_com/logs/error.log"
ScriptAlias /cgi-bin/ "d:/Websites/domain1_com/cgi-bin/"
<Directory "d:/Websites/domain1_com/www">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

<VirtualHost *:80>
# domain2.com virtual host.
ServerAdmin info@domain2.com
DocumentRoot "d:/Websites/domain2_com/www"
ServerName domain2.com
ServerAlias *.domain2.com
ErrorLog "d:/Websites/domain2_com/logs/error.log"
ScriptAlias /cgi-bin/ "d:/Websites/domain2_com/cgi-bin/"
<Directory "d:/Websites/domain2_com/www">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>


So far, everything works perfectly.

(3) Now, I added a virtual host for subdomain:

Quote:

# sub.domain2.com virtual host.
ServerAdmin info@sub.domain2.com
DocumentRoot "d:/Websites/sub_domain2_com/www"
ServerName sub.domain2.com:80
ServerAlias *sub.domain2.com
ErrorLog "d:/Websites/sub_domain2_com/logs/error.log"
ScriptAlias /cgi-bin/ "d:/Websites/sub_domain2_com/cgi-bin/"
<Directory "d:/Websites/sub_domain2.com/www">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>


(4) Here the problem comes. When I enter sub.domain2.com into browser, it shows domain1.com content.

(5) Based on some suggestions, I removed asterisks from ServerAlias lines. This made the subdomain working, but messed up the other two servers, which became unavailable or broken down.

Can you please help with this? Maybe a htaccess tweak would help. I am not a pro, so please be clear and put it the easy way.

Thanks!
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3094
Location: Hilversum, NL, EU

PostPosted: Mon 22 Apr '13 20:24    Post subject: Reply with quote

You are not telling which Apache version you use. Prior to 2.3.11, NameVirtualHost was required. Missing your default virtual host.

This works here:
Code:
# The first VirtualHost (default) is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.

<VirtualHost *>
    ServerName father
    ServerAlias localhost
    ServerAlias 127.0.0.1
    DocumentRoot d:/web/unknown
</VirtualHost>

<VirtualHost *>
    ServerName www.apachelounge.com
    ServerAlias apachelounge.com
    ServerAlias www.apachelounge.nl
    ServerAlias apachelounge.nl
    DocumentRoot d:/web/al
    .....
    .....
</VirtualHost>

<VirtualHost *>
    ServerName www.familieland.com
    ServerAlias familieland.com
    DocumentRoot d:/web/fam
    .....
    .....
</VirtualHost>

<VirtualHost *>
    ServerName www.doeke.familieland.com
    ServerAlias doeke.familieland.com
    DocumentRoot d:/web/doeke
    .....
    .....
</VirtualHost>
Back to top
cinciala



Joined: 22 Apr 2013
Posts: 5

PostPosted: Mon 22 Apr '13 21:33    Post subject: Reply with quote

Thanks!

Apache version is 2.4 - shown in the subject line of this topic.

Will test this and let you know.
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3094
Location: Hilversum, NL, EU

PostPosted: Mon 22 Apr '13 22:22    Post subject: Reply with quote

Sorry overlooked it.

Steffen
Back to top
cinciala



Joined: 22 Apr 2013
Posts: 5

PostPosted: Mon 22 Apr '13 22:53    Post subject: Reply with quote

Steffen,

Maybe a stupid question, but what exactly does the first virtual host do? (father = default virtualhost?)

<VirtualHost *>
ServerName father
ServerAlias localhost
ServerAlias 127.0.0.1
DocumentRoot d:/web/unknown
</VirtualHost>

In addition to those hosts, I have also configured virtual hosts for localhost (e.g. domain1_com.localhost). I assume I should update their configuration acc. to your suggestion, right?
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3094
Location: Hilversum, NL, EU

PostPosted: Mon 22 Apr '13 23:04    Post subject: Reply with quote

The default catches for example when your site is accessed by its IP address, localhost , an unknown sub domain etc. Father is just a name, so I see the accesses in the logs. And in DocumentRoot d:/web/unknown I have an index.html.

Steffen
Back to top
cinciala



Joined: 22 Apr 2013
Posts: 5

PostPosted: Mon 22 Apr '13 23:53    Post subject: Reply with quote

Tested, but got his:

Forbidden
You don't have permission to access / on this server.

for all domains and subdomain.

Any other suggestions?
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7373
Location: Germany, Next to Hamburg

PostPosted: Tue 23 Apr '13 10:49    Post subject: Reply with quote

The problem is the lag of the <Directory> block for the document roots.

example for apache 2.2 http://pastebin.com/t5t4gxjq

if you use 2.4 you have to use
Code:

Require all granted

instead of
Code:

Order allow,deny
Allow from all
Back to top
cinciala



Joined: 22 Apr 2013
Posts: 5

PostPosted: Tue 23 Apr '13 13:33    Post subject: Reply with quote

James Blond: Bingo, that worked!!!

You saved my life, thank you very much.
Back to top


Reply to topic   Topic: Unable to set subdomains in Apache 2.4 View previous topic :: View next topic
Post new topic   Forum Index -> Apache