1

I have seen this asked about few times, but surprisingly no solutions worked for me:

  • Yes, I have used "sudo a2ensite com.secondwebsite.conf"
  • Yes, I have used "sudo /etc/init.d/apache2 reload"
  • Yes, I have used "sudo /etc/init.d/apache2 restart"
  • Yes, I have tried putting both virtual hosts into one file (/etc/apache2/sites-available/default), adding "NameVirtualHost *:80" on top of it and removing it from "/etc/apache2/ports.conf"
  • Yes, I have used "sudo chmod 777 /var/www/secondwebsite"

Whatever I do, secondwebsite.com keeps showing firstwebsite.com. Does anyone have any idea what might be causing this?

Here is my "/etc/apache2/sites-available/default"

    <VirtualHost *:80>
            ServerAdmin admin@gmail.com
            ServerName firstwebsite.com
            ServerAlias www.firstwebsite.com

            DocumentRoot /var/www
            <Directory />
                    Options FollowSymLinks
                    AllowOverride None
            </Directory>
            <Directory /var/www/>
                    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>

            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

            Alias /static /home/user/firstwebsite/firstwebsite/static
            <Directory /home/user/firstwebsite/firstwebsite/static>
                    Order allow,deny
                    Allow from all
            </Directory>

            Alias /media /home/user/firstwebsite/firstwebsite/site_media/media
            <Directory /home/user/firstwebsite/firstwebsite/site_media/media>
                    Order allow,deny
                    Allow from all
            </Directory>

            <Directory /home/user/firstwebsite/firstwebsite>
                    Order allow,deny
                    Allow from all
            </Directory>

            WSGIDaemonProcess firstwebsite
            WSGIProcessGroup firstwebsite
            WSGIScriptAlias / /home/user/firstwebsite/firstwebsite/wsgi.py
    </VirtualHost>

My "/etc/apache2/sites-available/com.secondwebsite.conf"

    <VirtualHost *:80>
            ServerAdmin admin@gmail.com
            ServerName secondwebsite.com
            ServerAlias www.secondwebsite.com

            DocumentRoot /var/www/secondwebsite/public_html
            ErrorLog ${APACHE_LOG_DIR}/secondwebsite_error.log
            # Possible values include: debug, info, notice, warn, error, crit,
            # alert, emerg.
            LogLevel warn

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

My "/etc/apache2/ports.conf"

    # If you just change the port or add more ports here, you will likely also
    # have to change the VirtualHost statement in
    # /etc/apache2/sites-enabled/000-default
    # This is also true if you have upgraded from before 2.2.9-3 (i.e. from
    # Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and
    # README.Debian.gz

    NameVirtualHost *:80
    Listen 80

    <IfModule mod_ssl.c>
        # If you add NameVirtualHost *:443 here, you will also have to change
        # the VirtualHost statement in /etc/apache2/sites-available/default-ssl
        # to <VirtualHost *:443>
        # Server Name Indication for SSL named virtual hosts is currently not
        # supported by MSIE on Windows XP.
        Listen 443
    </IfModule>

    <IfModule mod_gnutls.c>
        Listen 443
    </IfModule>

Result of sudo /usr/sbin/apache2ctl -S

    VirtualHost configuration:
    wildcard NameVirtualHosts and _default_ servers:
    *:80                   is a NameVirtualHost
             default server firstwebsite.com (/etc/apache2/sites-enabled/000-default:1)
             port 80 namevhost firstwebsite.com (/etc/apache2/sites-enabled/000-default:1)
             port 80 namevhost secondwebsite.com (/etc/apache2/sites-enabled/com.secondwebsite.conf:1)
    Syntax OK
1

Your server alias doesn't seem to work as they are not reported by the command /usr/sbin/apache2ctl -S as it should be similar to

VirtualHost configuration:
    wildcard NameVirtualHosts and _default_ servers:
    *:80                   is a NameVirtualHost
             default server firstwebsite.com (/etc/apache2/sites-enabled/000-default:1)
             port 80 namevhost firstwebsite.com (/etc/apache2/sites-enabled/000-default:1)
                     alias www.firstwebsite.com
             port 80 namevhost secondwebsite.com (/etc/apache2/sites-enabled/com.secondwebsite.conf:1)
                     alias www.secondwebsite.com
    Syntax OK

Please provide your Apache version also.

Also there is no "Directory" configuration for /var/www/secondwebsite/public_html in your second virtual host. Try to put one.

  • Hey, thanks for quick response! My version is Apache/2.2.22 (Debian) I tried adding same directory config for /var/www/secondwebsite/public_html as I have for /var/www/, but that didn't change anything. – mpiekarz Jul 4 '17 at 10:39
  • Did you have a look at the answer here: serverfault.com/questions/212071/serveralias-not-working. From the ouput of the /usr/sbin/apache2ctl -S it seems that the default server is our first server and is loaded before the other vhost. As suggested in the answer try to rename the link from /etc/apache2/sites-enabled/000-default.conf to /etc/apache2/sites-enabled/z000-default.conf to ensure it is read after the other file. – DevOps Jul 4 '17 at 15:59
0

As for my experience this can happen in the following situation:

firstsite.com has dns 1.2.3.4 and ip in vhost 1.2.3.4 or *

secondsite.com has dns 1.2.3.4 and ip in vhost is 1.2.3.5.

Both 1.2.3.4 and 1.2.3.5 are ips of the problematic server and apache is listening on both ips.

BUT as for the few logs and details you provided it is hard to find if this is actually the case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.