0

I want to set up a main site, and a sub-domain for development, using apache2 VirtualHosts. This is what my site.conf virtual host file looks like:

<VirtualHost *:80>
        ServerName dev.example.com

        DocumentRoot /var/www/site/subdomain
        <Directory /var/www/site/subdomain >
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel debug

        CustomLog ${APACHE_LOG_DIR}/sub.log combined
</VirtualHost>

<VirtualHost *:80>
        ServerName www.example.com
        ServerAlias example.com

        DocumentRoot /var/www/site/main
        <Directory /var/www/site/main >
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

The problem is that every time I visit dev.example.com, I just get example.com.

I've tried all the other solutions I could find (using literal IPs, re-ordering things, using ports instead of named hosts)... I'm totally stuck now. Anyone got any ideas?

Edit: Here's my virtual host dump (the relevant part):

 port 80 namevhost dev.example.com (/etc/apache2/sites-enabled/example.conf:1)
 port 80 namevhost www.example.com (/etc/apache2/sites-enabled/example.conf:44)

Also, if I remove the main domain site, the subdomain site doesn't get detected at all.

Tspoon
  • 1
  • 3
  • In your config there should be a line like `NameVirtualHost *:80`. Is there such a line? – Jenny D Jul 01 '14 at 13:15
  • Also, you are using **either** apache-2.2 or apache-2.4. Please remove the tag pertaining to the version you're not using. – Jenny D Jul 01 '14 at 13:15
  • Yeah - that line is in the ports.conf I believe (I also tried adding it to the site config, but no luck there either). As for the tags - I actually tried it on both 2.2 & 2.4 with the same result. But I'll remove one anyway. – Tspoon Jul 01 '14 at 13:16
  • OK, next question - could you try running `httpd -S` and add the output to your question? – Jenny D Jul 01 '14 at 13:22
  • I'll do that as soon as I get home - I remember it gave me some stuff about undefined variables last time I tried, but I'll fix that and post the output. Thanks! Also I believe the command is `apache2 -S` in 2.4, for anyone else reading this. – Tspoon Jul 01 '14 at 13:46
  • On my server with apache 2.4, it's still `httpd -S`. – Jenny D Jul 01 '14 at 13:49
  • Hmm, I'll look into it this evening and get back to you. Thanks again! – Tspoon Jul 01 '14 at 13:51
  • @JennyD Attached the output to the original question, looks okay to me... Also, for future readers, Debian does not rename `apache2` to `httpd`, so you must use `apache2ctl -S` – Tspoon Jul 01 '14 at 16:57

2 Answers2

1

Make sure you enable your site with

a2ensite dev.mysite.com

Once you do this, a symlink to the config file is placed in the sites-enabled directory, which should allow the site to be accessed assuming no other issues exist.

This question gives a few more details.

Anaksunaman
  • 178
  • 9
0

Wordpress Was The Problem

Or rather, me not knowing that I had to configure the Wordpress site url to be the subdomain, otherwise it would just redirect to the domain given...

So the solution: open the wp_options table and edit the site_url to include the subdomain.

Tspoon
  • 1
  • 3