-2

I am paying for a Virtual Private Server with Linode. I recently set it up with apache to host two different websites. Now that I've added the sites, I can no longer access my index.html file at /var/www/. For some reason, my IP address points to the last site that I configured. Is there any way that I can have my sites point to their public folders, and my IP address point to the /var/www/ folder like it was when I set it up? I tried searching for an answer, but found nothing; perhaps I'm not sure what to search for.

Update

I realize that after going through the linode steps to hosting a website I deactivated the default file which pointed to the /var/www/ directory:

sudo a2dissite default

So I enabled it with

sudo a2ensite default
sudo service apache2 restart

This made the IP address serve up the files in the desired directory, but now the first site I enabled/configured also serves up the same default files (and no longer the site's files, as specified in /etc/apache2/sites-available/).

How can I have all three virtual hosts? Two name-based, and one IP-based?

bozdoz
  • 153
  • 2
  • 6
  • 3
    An IP address does not point to a directory structure. It is a machine address that hosts servers listening on various ports. In this case, you are wanting a web server to respond. And the last server you're setting up is responding. You need to look up setting up virtual hosting on your web server so multiple websites are served out by the same http server in addition to the original server that kept its files in /var/www/. The downvote is probably because the question makes absolutely no sense as per the above paragraph. – Fiasco Labs Sep 04 '13 at 05:47
  • 2
    The question does make sense, if you understand what is being asked. – Lawrence Sep 04 '13 at 06:11
  • Well, I've edited the question to try to make it more clear. I realize I'm lost, and new to this. And I have no idea how to make the question more useful. I haven't found anything helpful on this site, or searching Google. – bozdoz Sep 04 '13 at 06:52

2 Answers2

1

You can setup 3 virtual hosts -
<VirtualHost *:80>
ServerName x.x.x.x
DocumentRoot /var/www
</VirtualHost>
 
<VirtualHost *:80>
ServerName name1
DocumentRoot /var/www/name1
</VirtualHost>
 
<VirtualHost *:80>
ServerName name2
DocumentRoot /var/www/name2
</VirtualHost>

Lawrence
  • 380
  • 2
  • 10
  • I have that. It's still only serving up two of the three sites. – bozdoz Sep 04 '13 at 06:50
  • Can you put the config file onto pastebin or something so we can see it ? – Lawrence Sep 04 '13 at 07:01
  • @bozdoz It sounds like you are trying to configure [**name-based virtual hosting**](http://httpd.apache.org/docs/2.2/vhosts/name-based.html). The problem you're describing (only one configured site showing up when you have multiple `` definitions for a specific host/port) is usually because you are missing the `NameVirtualHost` directive, or because you're trying to access the site by IP (e.g. `http://10.0.0.1`) instead of name: Without the name Apache serves the first matching site it finds in its configuration. – voretaq7 Sep 04 '13 at 19:09
  • I am trying to access the site by IP. I also have two others I want to have accessible by domain name. @voretaq7 – bozdoz Sep 04 '13 at 19:30
  • @bozdoz [Windmills do not work that way](http://www.youtube.com/watch?v=ZQg8JKo_3ZQ) -- You must pick either Address-based virtual hosting (a separate IP for each site, and configure your server that way. You will be able to access sites by IP or Domain Name and they'll work either way), or Name-based virtual hosting (using `NameVirtualHost` and `ServerName` and accessing sites by *domain name only* so that an appropriate `Host:` header is presented to the server). See the docs I linked to previously. – voretaq7 Sep 04 '13 at 19:50
  • @voretaq7 Do you mean that you cannot use IP address AND hostname to get apache to serve up different sites ? – Lawrence Sep 05 '13 at 00:54
  • @Lawrence No. I mean exactly what I said above. Name-based virtual hosting allows multiple sites on a single IP address, but it ***requires*** a HTTP `Host` header to work properly (therefore it requires that the site be accessed using a domain name - specifically one that matches the `ServerName` or `ServerAlias` defined for that virtual host). IP-based virtual hosting does not require the `Host` header, and will therefore work regardless of whether you access a site by name or IP address, however IP-based virtual hosting requires a separate IP address for each `VirtualHost`. – voretaq7 Sep 05 '13 at 06:38
0

as far as I understood you have some kind of debian\ubuntu installed there?

sites-avalable intended to contain config for sites that can be run at your server, directory for sites that actually run at your server is sites-enabled.

You can create symlink manually or use command a2ensite mysite which will do all necessary work for you

More details here

strange walker
  • 582
  • 3
  • 10