Virtualhost Apache on Ubuntu server not working

こ雲淡風輕ζ 提交于 2019-12-11 17:32:50

问题


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:

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?

来源:https://stackoverflow.com/questions/49085166/virtualhost-apache-on-ubuntu-server-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!