By Ivailo
I have the WordPress one click install app image and I need to fix some problems with the default server.
I have two sites enabled. Let’s call them site-a and site-b with the requisite config files at /etc/apache2/sites-available/site-a.conf and site-b.conf. Both sites are enabled so symlinks to these files appear at /etc/apache2/sites-enabled/
Both sites are running as they should except for one big problem - apache is closing one of the two sites to be the “default” site at random and it’s choosing exactly the one I don’t want.
Nothing I’ve tried is fixing this. I thought that I just needed to put in the top line of the site I want to be the default this: " <VirtualHost default:80>" but it isn’t working.
What do I have to do here?
Here are my two config files, nothing special.
Site A:
<VirtualHost *:80>
ServerName site-a.com
ServerAlias site-a.com www.site-a.com
ServerAdmin webmaster@site-a.com
DocumentRoot /var/www/html/site-a.com
<Directory /var/www/html/site-a.com>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/site-a_error.log
CustomLog ${APACHE_LOG_DIR}/site-a_access.log combined
</VirtualHost>
Site B:
<VirtualHost *:80>
ServerName secondary.site-a.com
ServerAdmin webmaster@secondary.site-a.com
DocumentRoot /var/www/html/site-b.com
<Directory /var/www/html/site-b.com>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/site-b_error.log
CustomLog ${APACHE_LOG_DIR}/site-b_access.log combined
</VirtualHost>
Now all I want is for the server to serve up Site A when in doubt. I only want it to serve up Site B when somebody enters exactly http://secondary.site-a.com or http://secondary.site-a.com/some/url/at/subodain/secondary
The problem is it’s doing the opposite. How do I fix this?
Thanks.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
“Do you have a file named secondary.site-a.com in apache2/sitesenabled ?”
Yes.
“Also when you say “when in doubt” do you mean you would like your server site-a.com to be redirected to as long as someone chooses anything.site-a.com other than secondary.site-a.com?”
I mean when somebody visits anything besides http://secondary.site-a.com or http://secondary.site-a.com/some/url/of/this/subdomain I do NOT want that site to be displayed for any reason. This includes visiting the IP address http://123.123.123.123
It treats the config files in a top-down approach. It will default to the first vhost based upon alpahbet (if no numbers are present), or the lowest number config file.
For example:
000-default.conf
test.com.conf
site-a.com.conf
site-b.com.conf
In the above, 000-default will be the default, because it goes “numbers, then letters”.
To see which one is being used:
apache2ctl -S
This comment has been deleted
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.