bbwhited
By:
bbwhited

Ubuntu 16.04 Apache2 multiple websites

March 1, 2017 1.4k views
Apache Ubuntu 16.04

I've follow everything to the letter for the tutorial
sudo a2ensite olmacdoanldsfarm.com /var/www/html already enabled
sudo a2ensite peapatchrvpark.com /var/www/peapatch/ already enabled
sudo a2ensite redpoppyrentalhall.com /var/www/redpoppy/ already enabled
sudo dissite default already disabled
etc/hosts
127.0.0.1 olmacds localhost
192.168.1.29 olmacdonaldsfarm.com
192.168.1.29 peapatchrvpark.com
192.168.1.29 redpoppyrentalhall.com
192.168.1.29 is the address of my server on my private network
65.245.187.152 is the address of my public ip
it serves olmacdonaldsfarm.com 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...?

3 Answers
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 redpoppyrentalhall.com.conf 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.

redpoppyrentalhall.com.conf

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

  • 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//65.245.187.152 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 redpoppyrentalhall.com which was redpoppyrentalhhall.com 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 peapatchrvpark.com
          then disabled peapatchrvpark.com
          and it loaded redpoppyrentalhall.com

          so enabled all three sites
          now serves olmacdonaldsfarm.com as all three sites
          so did sudo nano /etc/hosts
          added
          127.0.0.1 olmacdonaldsfarm.com
          127.0.0.1 redpoppyrentalhall.com
          127.0.0.1 peapatchrvpark.com

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

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

  • Okay, so everything is good now?

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

      • 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 127.0.0.1 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>
        ServerName www.olmacdonaldsfarm.com
        ServerAlias olmacdonaldsfarm.com
        DocumentRoot /var/www/html
        
        <VirtualHost *:80>
        ServerName www.redpoppyrentalhall.com
        ServerAlias redpoppyrentalhall.com
        DocumentRoot /var/www/redpoppy
        
        <VirtualHost *:80>
        ServerName www.peapatchrvpark.com
        ServerAlias peapatchrvpark.com
        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 65.245.187.152
          ip address of server 192.168.1.29
          port 80 in residential gateway pointed at 192.168.1.29

          • 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 65.245.187.152 is your public IP.
            You'll be redirecting traffic to that IP, then you firewall allows port 80 traffic to pass thru to 192.168.1.29.

          • @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.

Have another answer? Share your knowledge.