Trouble Getting 2nd Vhost to work

I do this day in and day out at DigitalOcean using Apache2 on Ubuntu 16. For the life of me, I can't get a 2nd Vhost to work here on Linode - it goes to the first Vhost set up every time. Here is the output of apache2ctl -S:

VirtualHost configuration:
*:443                  shockalarm.com (/etc/apache2/sites-enabled/shockalarm.com.conf:7)
*:80                   synergyitgroup.net (/etc/apache2/sites-enabled/synergyitgroup.net.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: using_defaults
Mutex ssl-stapling: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33

Here is shockalarm's conf file:

 <virtualhost *:80="">ServerName shockalarm.com/
        Redirect permanent / https://shockalarm.com/</virtualhost> 

 <ifmodule mod_ssl.c=""><virtualhost *:443="">ServerName shockalarm.com
                ServerAlias www.shockalarm.com
                ServerAdmin webmaster@localhost
                DocumentRoot /var/www/shockalarm.com/public_html
                <directory var="" www="" shockalarm.com="" public_html="">Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all</directory> 
                ErrorLog /var/www/shockalarm.com/logs/error.log
                CustomLog /var/www/shockalarm.com/logs/access.log combined
                SSLEngine On
                SSLCertificateFile      redacted
                               SSLCertificateKeyFile redacted
                               SSLCertificateChainFile redacted</virtualhost></ifmodule> 

Here is Synergy's conf file (SSL not enabled yet)

 <virtualhost *:80="">ServerName synergyitgroup.net
    ServerAlias www.synergyitgroup.net
    ServerAdmin webmaster@synergyitgroup.net
    DocumentRoot /var/www/synergyitgroup.net/public_html
     <directory var="" www="" synergyitgroup.net="" public_html="">Options Indexes FollowSymLinks Multiviews
        AllowOverride All
        Order allow,deny
        allow from all</directory> 
    ErrorLog /var/www/synergyitgroup.net/logs/error/.logs/error.log
    CustomLog /var/www/synergyitgroup.net/logs/error/.logs/access.log combined</virtualhost> 

Any clue as to what I'm doing wrong??? Thanks in advance for helping this rookie out!

6 Replies

For shockalarm's config file there's a few things that strike me as out of the ordinary. A few of them may just be formatting conventions, but could you try running the config file like this?

 <virtualhost *:80="">ServerName shockalarm.com/
        ServerAlias www.shockalarm.com/
        Redirect permanent / https://shockalarm.com/</virtualhost> 

 <virtualhost *:443=""><ifmodule mod_ssl.c="">SSLEngine On
            SSLCertificateFile /etc/ssl/certs/STAR_shockalarm_com.crt
                SSLCertificateKeyFile /etc/ssl/private/STAR_shockalarm.com.key
                SSLCertificateChainFile /etc/ssl/certs/STAR_shockalarm_com.ca-bundle.crt

                ServerName shockalarm.com/
                DocumentRoot /var/www/shockalarm.com/public_html

                <directory var="" www="" shockalarm.com="" public_html="">Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order Allow,Deny
                Allow from all</directory> 

                ErrorLog /var/www/shockalarm.com/logs/error.log
                CustomLog /var/www/shockalarm.com/logs/access.log combined</ifmodule></virtualhost> 

Made the changes, below. Reloaded the conf files and restarted apache. http://synergyitgroup.net still goes to https://shockalarm.com

:?

@mtjones:

For shockalarm's config file there's a few things that strike me as out of the ordinary. A few of them may just be formatting conventions, but could you try running the config file like this?

 <virtualhost *:80="">ServerName shockalarm.com/
        ServerAlias www.shockalarm.com/
        Redirect permanent / https://shockalarm.com/</virtualhost> 

 <virtualhost *:443=""><ifmodule mod_ssl.c="">SSLEngine On
            SSLCertificateFile /etc/ssl/certs/STAR_shockalarm_com.crt
                SSLCertificateKeyFile /etc/ssl/private/STAR_shockalarm.com.key
                SSLCertificateChainFile /etc/ssl/certs/STAR_shockalarm_com.ca-bundle.crt

                ServerName shockalarm.com/
                DocumentRoot /var/www/shockalarm.com/public_html

                <directory var="" www="" shockalarm.com="" public_html="">Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order Allow,Deny
                Allow from all</directory> 

                ErrorLog /var/www/shockalarm.com/logs/error.log
                CustomLog /var/www/shockalarm.com/logs/access.log combined</ifmodule></virtualhost> 

Just a thought… do I have to use Linode's DNS servers to make this work? I currently use DNSMadeEasy for all of my clients…

Taking another look I think there's a redirect set up somewhere in the document root or CMS for http://synergyitgroup.net as it's being redirected by Apache:

curl http://synergyitgroup.net

<title>301 Moved Permanently</title>

# Moved Permanently

The document has moved [here](https://shockalarm.com/).

* * *

<address>Apache/2.4.18 (Ubuntu) Server at synergyitgroup.net Port 80</address>

Are you using any CMS such as Drupal or WordPress? You may want to check any .htaccess files in the document root for http://synergyitgroup.net for a redirect, or check the settings of your CMS to see if the site name or URL is set differently.

Here's the guide for changing the site URL in WordPress, just in case: https://codex.wordpress.org/ChangingTheSite_URL

I am also seeing the redirect as well. There are a few things to check. First you should check the access logs for http://synergyitgroup.net and see if it is showing anything. you can ssh to your box and run the command "tail -f /var/www/synergyitgroup.net/logs/error/.logs/access.log" then ssh to your box again (new window/terminal) and run "tail -f /var/www/shockalarm.com/logs/access.log"

attempt to access http://synergyitgroup.net. after going to your site look at which log file logs the connection. should be logged under "/var/www/synergyitgroup.net/logs/error/.logs/access.log"

As previously stated you will also need to check for any redirects in your .htaccess file if present.

Another thing to check that happened to me, is the file encoding for the config files. your config files should be encoded as unix files and not dos/windows. The problem was caused by using notepad++ in windows to create the config files and then upload the files to my server via ftp. I originally didn't think about that and if I had I could have switched the files to use unix encoding in notepad++.

I was using nginx as the front end server and apache for the backend. I had 2 domains configured that was causing trouble. kb.example.org and kb.example.com. For some reason both domains were pointing to the same site example.com. After checking both sites access log files I found out that nginx was processing kb.example.com under the correct host but for some reason kb.example.org was being processed under example.com and not kb.example.org. The underlying issue for me was the file encoding. My files was using dos encoding causing nginx to parse the config files incorrectly. I had to convert the encoding to unix and restart nginx to fix the issue.

The first vhost configuration item that Apache reads is considered the default one. Your 2nd virtualhost is not matched by Apache, thereby falling through to default; hence, post your entire configuration. Note that ServerName/ServerAlias must not contain slashes like yours does.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct