It's the only way I ever do it... over many years.
You were right. Each and every vhost has to be in its own, separate, independent configuration file. Why this is, I do not know.
I was used to the old apache behavior, where config files were config files, and their contents defined the behavior, not their placement or name; the vhost directory was just an invitation to organize them better. Is this an ubuntu thing, or has apache changed that drastically?
In any case, solved. Thank you.
My config files, for posterity:
/etc/apache2/sites-available/mysite.com:
<VirtualHost *:80>
ServerName mysite.com
DocumentRoot /usr/share/wordpress
</VirtualHost>
Each individual subdomain is like /etc/apache2/sites-available/subdomain.mysite.com:
<VirtualHost *:80>
ServerName subdomain.mysite.com
DocumentRoot /usr/share/wordpress
alias /wp-content/languages /srv/www/wp-content/subdomain.mysite.com/languages
alias /wp-content/plugins /srv/www/wp-content/subdomain.mysite.com/plugins
alias /wp-content/themes /srv/www/wp-content/subdomain.mysite.com/themes
alias /wp-content/uploads /srv/www/wp-content/subdomain.mysite.com/uploads
</VirtualHost>
Then you can
a2ensite mysite.com
a2ensite subdomain.mysite.com
service apache2 reload
to get the virtual hosts online.
Hi Corona look at the following... this time you will get what you want
root@Aix:/etc/apache2/sites-available# ls
akshay corona default default-ssl
root@Aix:/etc/apache2/sites-available# cat default
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options -Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
root@Aix:/etc/apache2/sites-available# cat akshay
<VirtualHost *:80>
ServerName akshay.com
DocumentRoot /var/www/akshay
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/akshay/>
Options -Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
root@Aix:/etc/apache2/sites-available# cat corona
<VirtualHost *:80>
ServerName corona.com
DocumentRoot /var/www/corona
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/corona/>
Options -Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
root@Aix:/var/www# ls
akshay corona
root@Aix:/var/www# cat akshay/index.html
<html>
<head>
<title>akshay.com</title>
</head>
<body>
akshay.com
</body>
</html>
root@Aix:/var/www# cat corona/index.html
<html>
<head>
<title>corona.com</title>
</head>
<body>
corona.com
</body>
</html>
root@Aix:/var/www# cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 Aix
127.0.0.1 akshay.com
127.0.0.1 corona.com
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
root@Aix:/var/www# sudo a2ensite akshay
Site akshay already enabled
root@Aix:/var/www# sudo a2ensite corona
Site corona already enabled
root@Aix:/var/www# sudo a2dissite default
Site default already disabled
root@Aix:/var/www# sudo /etc/init.d/apache2 reload
* Reloading web server config apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
clear cache and checkout corona.com
and akshay.com
on your browser
Hey Brother,
I don't know, but it's been this way for many years; but I only use Ubuntu, so I cannot speak for other Linux distributions.
However, those commands like:
a2ensite your.cool.site.com
... are apache2 commands ( I think ) , not specific to Ubuntu (I did not confirm this, however), and those commands take a file in ../sites-available
and simply create a symlink from ../sites-enabled
.
Anyway, it's all moot now, since you got it working!
OBTW, in one of the example posts above, each virtualhost file has the same log file directive:
CustomLog ${APACHE_LOG_DIR}/access.log combined
I know it's only an example, but just for the record, I recommend that you always keep separate access log and error log files for each virtual host and do not use the same file for all virtual hosts, combined into one log file.
I always have separate log file (access and error) with names that correspond to each virtual server.
These days, I'm getting so I put each logging (for each web site) in it's own directory (apache2, mysql, various site specific debug logs, etc) ; but that's not as important as just making sure your access and error logs are specific for each virtual host.
Yes... Neo.. I just pasted same file and changed server name so.. as you said it's always good if there is a separate log file for access and error.
All Ubuntu has is Include sites-enabled/
at the end of apache2.conf, which means 'concatenate everything inside sites-enabled then parse'. Not far different from the default configs on my other servers really. The apache documentation appears to agree, there's no extra magic to it.
I'm beginning to think I just fat-fingered something in my first attempts and got myself confused, stuck in a blind alley. A combined config should still work hypothetically. But I've been fighting with this so long I'm just thrilled that it works at all.
I will further refine these vhosts now that I have something that works, thank you for your suggestions. I kept them intentionally as simple as possible to rule out other problems.
Yes, I understand. As mentioned, I wanted to point out that this was "an example" and not best practices. Ditto for having the same logfile for each virtual host as the same.
There are other included directories like:
/etc/apache2/conf.d
.. and my experience is that we need to be caution when running many sites together and using these Include
directives for directories.
For example, on many of my sites, I have a separate directive to include files are specific to each web site and only keep the "bare bones" files that must be common to each site in the common Include conf.d directory.
I have spent many an hour trying to fix problems related to these Include directives on a server running many "sites"...