1

I have read several articles and combed over stackExchange, but could not resolve the issue. I have two domain names, and I want to create virtual hosts for each of them. I have created separate folders, where i host the index.html for each domain. I have also created a conf file, under /etc/apache2/sites-available the files is as follows:

NameVirtualHost x.x.x.x:80

<VirtualHost x.x.x.x:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        ServerName example1.org
        ServerAlias www.example1.org
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/org/public_html
        #Options +FollowSymlinks
        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn
        #<Directory /var/www/html/org/public_html>
        # Options -Indexes +FollowSymLinks +MultiViews
        # AllowOverride All
        # Require all granted
        #</Directory>

        LogLevel warn

        ErrorLog ${APACHE_LOG_DIR}/example1aorg-error.log
        CustomLog ${APACHE_LOG_DIR}/example1org-access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>



<VirtualHost x.x.x.x:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        ServerName example2.com
        ServerAlias www.example2.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/com/public_html
        #Options +FollowSymlinks
        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn
        #<Directory /var/www/html/com/public_html>
        # Options -Indexes +FollowSymLinks +MultiViews
        # AllowOverride All
        #</Directory>

        LogLevel warn

        ErrorLog ${APACHE_LOG_DIR}/example2com-error.log
        CustomLog ${APACHE_LOG_DIR}/example2com-access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

x.x.x.x is the public IP
example1 and example2 are not the domains I am working with, but just dummy domains.

When I try to load the domain on my server, the server always shows me the index file for example1.

I am not sure what to do, it seems like the virtual host is not going to work with two domains.

Edit: I still cannot figure this out, here are my domain names: www.asanteniafrica.com www.asanteniafrica.org

I want to believe this is something to do with the .org and .com part of the domain, I am still researching.

  • Best is to test with curl example1.com and curl example2.com or open your browser in private / incognito mode. I often got bitten by the browser cache showing me wrong results. Also check with curl -IL example1.com and curl -IL example2.com if there is a redirect happening. As @scuba_mike already mentioned, look at your log files. – Thomas Aug 24 at 9:48
  • @Thomas so I did as you suggested, i executed the curl commands on both domains. I accessed the access logs of both virtual hosts, the only log that includes any new logs (based on executing the curl commands) is the example1.org access logs, example2.com have not registered any new logs. – Ruwenzori Aug 24 at 19:33
  • @Thomas here are the results of curl -IL command, both domains produce the same results. – Ruwenzori Aug 24 at 19:36
0

If you're installing via apt, you may need to check to see if there is a default configuration. If there is, you should disable it by removing it from the sites-enabled list.

Without seeing how example1.com is configured, it's hard to tell where the problem is. But if it's set up just like example2.com, ensure that DocumentRoot is pointing to a different directory. It's easy to overlook.

Quick edit: VirtualHosts will definitely work for more than one domain. I'm currently running it with three domains and several sub-domains, all with VirtualHost. SSL is tricky though...but that's off topic.

+++

Additional edit after providing example1.com configuration.

Without the comments, it looks like you're configuration is like this:

NameVirtualHost x.x.x.x:80

<VirtualHost x.x.x.x:80>
        ServerName example1.org
        ServerAlias www.example1.org
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/org/public_html

        LogLevel warn

        ErrorLog ${APACHE_LOG_DIR}/example1aorg-error.log
        CustomLog ${APACHE_LOG_DIR}/example1org-access.log combined
</VirtualHost>



<VirtualHost x.x.x.x:80>
        ServerName example2.com
        ServerAlias www.example2.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/com/public_html

        LogLevel warn

        ErrorLog ${APACHE_LOG_DIR}/example2com-error.log
        CustomLog ${APACHE_LOG_DIR}/example2com-access.log combined
</VirtualHost>

The diff between these, besides the domains, is org for example1 and com for example2. Does example2 have logs when you visit it from the browser? Can you provide those as well?

  • sorry for the late reply, the access logs for example2.com are here – Ruwenzori Aug 24 at 19:20
  • here are the access logs for example1.org – Ruwenzori Aug 24 at 19:25
  • The access logs are hours apart. It's hard to tell what is happening between example1 and example2. If going to example2 shows example1 information, you would either see traffic only going to example1 or a redirect (301,302) to example1. The good news is example2 is returning 200 error codes, which means success. But without access logs that are closer together, it's hard to tell where the problem is. – scuba_mike Aug 25 at 13:44
0

Alright, after searching and rebuilding my server, I finally found the answer to my problem. I was actually forwarding my server I.P. to my domain, instead of configuring the DNS. I bought my domain from GoDaddy, and my server is with Linode. I followed the following directions to configure my DNS.

https://www.linode.com/docs/platform/manager/dns-manager/

Then, logged into Godaddy.com and added the Nameservers to my domain, using the following guide:

https://www.godaddy.com/help/set-nameservers-for-domains-hosted-and-registered-with-godaddy-12316

Once I updated the Nameservers, it took about 48 hours for the URL to point at the correct webroot via the browser.

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.