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

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.

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