0

Hi I got to domains pointing to one server IP. The server is a VPS server running Ubuntu and Apache2.

Now I am trying to host two different sites using Virtualhost.

These are the steps I used to try and setup virtual hosting:

root@vps520749:~# sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/                                                                                                                                                                    root@vps520749:~# sudo cp /etc/apache2/sites-available/000-default.conf     /etc/apache2/sites-available/levsite.nl.conf
root@vps520749:~# sudo nano /etc/apache2/sites-available/levsite.nl.conf
root@vps520749:~# sudo cp /etc/apache2/sites-available/levsite.nl.conf /etc/apache2/sites-available/informaticaproject.nl.conf
root@vps520749:~# sudo nano /etc/apache2/sites-available/informaticaproject.nl.conf
root@vps520749:~# sudo a2ensite levsite.nl.conf
Enabling site levsite.nl.
To activate the new configuration, you need to run:
  service apache2 reload
root@vps520749:~# sudo a2ensite informaticaproject.nl.conf
Enabling site informaticaproject.nl.
To activate the new configuration, you need to run:
  service apache2 reload
root@vps520749:~# sudo a2dissite 000-default.conf
Site 000-default disabled.
To activate the new configuration, you need to run:
  service apache2 reload
root@vps520749:~# sudo systemctl restart apache2
root@vps520749:~# sudo service apache2 restart
root@vps520749:~# sudo service apache2 reload
root@vps520749:~# sudo nano /etc/apache2/sites-available/informaticaproject.nl.conf
root@vps520749:~# sudo a2ensite informaticaproject.nl.conf
Site informaticaproject.nl already enabled
root@vps520749:~# sudo a2ensite levsite.nl.conf
Site levsite.nl already enabled
root@vps520749:~# sudo nano /etc/apache2/sites-available/levsite.nl.conf
root@vps520749:~# sudo a2dissite 000-default.conf
Site 000-default already disabled

The file structure I use looks like this: file structure

This is the levsite.nl.conf:

<VirtualHost *: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 www.example.com

    ServerAdmin admin@levsite.nl
    ServerName levsite.nl
    ServerAlias www.levsite.nl
    DocumentRoot /var/www/levsite.nl/public_html

    # 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

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/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>

The informaticaproject.nl.conf:

<VirtualHost *: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 www.example.com

    ServerAdmin admin@informaticaproject.nl
    ServerName informaticaproject.nl
    ServerAlias www.informaticaproject.nl
    DocumentRoot /var/www/informaticaproject.nl/public_html

    # 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

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/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>

But it's still not working, wether I use levsite.nl to access the server or informaticaproject.nl to access the server I am always pointed to /var/www/informaticaproject.nl/public_html....

What am I missing here?

lmiv
  • 315
  • 5
  • 17
  • what is the output of `sudo apache2 -S`? – Andra Mar 03 '18 at 17:07
  • https://puu.sh/zzKcx/ba7d6bae05.png this is the output – lmiv Mar 03 '18 at 17:09
  • it's obviously smth wrong. Google _AH00111: Config variable is not defined_. – Andra Mar 03 '18 at 17:13
  • I found this post: https://serverfault.com/questions/558283/apache2-config-variable-is-not-defined/671140 but by editing the `/etc/apache2/apache2.conf` file it still doesnt work... – lmiv Mar 03 '18 at 17:28
  • What do you think it could be I tried almost everything google suggests @Andra – lmiv Mar 03 '18 at 17:43
  • do you have a file /etc/apache2/envvars ? And how do you start apache? – Andra Mar 03 '18 at 17:46
  • @Andra Yes I have a file `/etc/apache2/envvars`. I start Apache like this `sudo service apache2 start` – lmiv Mar 03 '18 at 17:51
  • See in `envvars` these 5 variables, which `apache2 -S` says are not defined. Are they present? Put here, for example, the line with APACHE_LOG_DIR. – Andra Mar 03 '18 at 17:54
  • https://puu.sh/zzM8V/4eab4f3bac.png they are in the `envvars` file... – lmiv Mar 03 '18 at 17:57
  • the contents of apache2.conf ? – Andra Mar 03 '18 at 18:04
  • https://pastebin.com/2tW28HYx – lmiv Mar 03 '18 at 18:14
  • thats my apache2.conf – lmiv Mar 03 '18 at 18:14
  • I compared it to my apache2.conf. First, I have commented out #ServerRoot "/etc/apache2", secondly, after `#` there are more lines including, for example, `IncludeOptional sites-enabled/*.conf`. – Andra Mar 03 '18 at 18:24
  • @Andra can you send your conf file so I can copy it? – lmiv Mar 03 '18 at 18:26
  • first, put this line `IncludeOptional sites-enabled/*.conf` at the end of your file – Andra Mar 03 '18 at 18:28
  • @Andra Okay I added `IncludeOptional sites-enabled/*.conf` but I am still getting the same error when I run `apache2 -S` – lmiv Mar 03 '18 at 19:14
  • sudo a2dissite. What are your choices? Do disabling, enabling anew, restart apache. Maybe you can restate the problem (ask another question). – Andra Mar 03 '18 at 19:26
  • this is how the file looks right now: https://pastebin.com/D8MhDeME – lmiv Mar 03 '18 at 19:27
  • `root@vps520749:~# sudo a2dissite Your choices are: informaticaproject.nl levsite.nl Which site(s) do you want to disable (wildcards ok)?` – lmiv Mar 03 '18 at 19:28
  • did you disable them and enable anew, and restart apache? – Andra Mar 03 '18 at 19:35
  • @Andra https://pastebin.com/gZf1kwmt nope still getting the same error :thinking: – lmiv Mar 03 '18 at 19:48
  • Do you access your page with levsite.nl? Then maybe you need clear DNS cache, browser cache. Can you start all **from the startpoint** - disable your sites, make sure that you cannot open them, but instead some page in default site. – Andra Mar 03 '18 at 19:58
  • why there is no Directory section for VirtualHost? sorry that I notice this so late. – Andra Mar 03 '18 at 20:02
  • idk how can i create a directory section for virtualhost? When I disable `levsite.nl` and `informaticaproject.nl` and restart apache I am directed to `/var/www/html/` – lmiv Mar 03 '18 at 20:15
  • @Andra I created a new post – lmiv Mar 04 '18 at 19:45
  • @Andra could it also be something with my DNS? – lmiv Mar 06 '18 at 01:11
  • Well, I didn't try to open your pages the other day. Now I do it and get "ULTIEME Virtual etc" for http://levsite.nl/ and "Sample "Hello, World etc" for http://informaticaproject.nl/. Definitely, different pages. Have you resolved the problem with opening only one location on the disk? – Andra Mar 06 '18 at 12:12
  • I reset the DNS and reconfigured it. Reinstalled Apache and started it with `apachectl -k start -S`. Added a couple of lines to `envvars`. Apparently that did the trick. – lmiv Mar 06 '18 at 12:18

0 Answers0