Ubuntu 16.04 Apache2 multiple websites

Posted March 1, 2017 83.1k views
ApacheUbuntu 16.04

I’ve follow everything to the letter for the tutorial
sudo a2ensite /var/www/html already enabled
sudo a2ensite /var/www/peapatch/ already enabled
sudo a2ensite /var/www/redpoppy/ already enabled
sudo dissite default already disabled
etc/hosts olmacds localhost is the address of my server on my private network is the address of my public ip
it serves just fine
not the other two
ive tried everything I have given up

1 comment
  • Can you please link to the tutorial you followed?
    And why did you edit /etc/hosts - that shouldn’t be changed normally…?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

3 answers
by Brennen Bearnes
The Apache web server is the most popular way to serve web content on the internet. Apache has the ability to serve multiple domains from a single server by using a mechanism called "virtual hosts". If a virtual host is configured correctly for each domain, the web server can correctly route traffic to the appropriate files based on the domain name requested. In this guide, we'll demonstrate how to configure Apache virtual hosts on an Ubuntu 16.04 server.
  • Okay. Like it says in step 6, it’s optional and something you need to do on your local computer.

    So go and undo the changes you made to /etc/hosts on the server.

    Then go to /etc/apache2/sites-enabled/ and copy configuration of the file and paste it here, so we can help figuring it out. I can see it’s doing some weird redirect, which is probably the same problem for the other ones.

<VirtualHost *:80>
DocumentRoot /var/www/redpoppy
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride None
<Directory /var/www/redpoppy/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

  • Great. You’re missing a > in the last </Directory but actually you can remove that entire directory-block, since it’s the same as just above.
    I’m still not sure why it’s doing the redirecting to http://http// which is incorrect in several ways. Have you any /var/www/redpoppy/.htaccess file that is doing something or have you a CMS system (WordPress, etc) doing a redirect?

    • ive fixed that </Directory error and the misspelling of which was at one time and did service apache2 restart and reload and did status to make sure the webserver was serving the pages
      and no I am not that advanced I don’t have any .htaccess files yet

      • Try disabling every other site, so you just start with one to begin with. Then look through each configuration and make sure there’s no errors (like there was in this one) and activate them one-by-one.
        Before doing service apache2 restart, run service apache2 configtest to make sure the configuration files are okay.

        • okay disabled olmacdonaldsfarm
          and it loaded
          then disabled
          and it loaded

          so enabled all three sites
          now serves as all three sites
          so did sudo nano /etc/hosts

          • You need to remove the lines you’ve added to /etc/hosts - there should only be one line containing and that has the name “localhost” in it.

okay I found the issue you were talking about http://http://
that’s at forwarding, I fixed that
now my server serves same index for all three sites

  • Okay, so everything is good now?

    • server serves to all three sites
      how to fix
      do I need to add listen 80 for 79 78 in ports.conf and then fix my forwarding to include port number at godaddy?

      • No, you can listen on the same port for different domains.

        You need to fix your /etc/hosts, which you modified on the server. There should only be one line with and that line contains “localhost”.

        Do not touch ports.conf or anything else. It’s fairly simple to setup domains in Apache, but you should only modify httpd.conf and the sites-enabled-conf’s (this is where the tutorial might have misled you).

        Make sure all your conf’s in /etc/apache2/sites-enabled/ different top-parts as such, where ServerName and DocumentRoot are the important ones:

        <VirtualHost *:80>
        DocumentRoot /var/www/html
        <VirtualHost *:80>
        DocumentRoot /var/www/redpoppy
        <VirtualHost *:80>
        DocumentRoot /var/www/peapatch
      • And you should not have any forwarding from GoDaddy. You need to setup each domain with an A-record pointing to the IP-address of your droplet.

        • I have server in my home
          not using a droplet
          ip address
          ip address of server
          port 80 in residential gateway pointed at

          • Okay, same thing - you need to create an A-record pointing to the public IP-address of the server/droplet.

            By the way, the tutorials at DigitalOcean is not really created for use on different setups - like home servers - unless you know how to convert/read them. They’re written as a step-by-step guide, which can quickly go in a wrong direction if you’re using a different setup (that being a home server or a server at another provider).

          • Then is your public IP.
            You’ll be redirecting traffic to that IP, then you firewall allows port 80 traffic to pass thru to

          • @bbwhited
            PS. If you edit comments after you’ve submitted them, then I don’t get a notification and several times you’ve added a lot of critical extra information. Create a new comment instead.

Submit an Answer