Apache Showing Default page VHOST Page

风格不统一 提交于 2020-01-05 10:27:11

问题


I've added some sites through virtual host like this, I have also specified their document route. I added all the content there, but for some reason when I visit the site through the browser the Apache default page is showing up.

<VirtualHost *:80>
    ServerAdmin admin@mydomain.com
    DocumentRoot "/var/www/html/mydomain/public_html"
    ServerName mydomain.com
    ServerAlias www.mydomain.com
    ErrorLog "/var/log/httpd/mydomain/error_log"
    CustomLog "/var/log/httpd/mydomain/access_log" common
</VirtualHost>

If anyone has any clue what's wrong, please let me know!


回答1:


Your ServerName is mydomain.com, but I assume you're trying to connect to it typing "localhost" on your browser. This way apache will use the default vhost instead of yours, which is probably defined on /etc/apache/sites-enabled/default.

What you can do is set mydomain.com to point to localhost. On Linux edit the /etc/hosts file adding the following line:

127.0.0.1   mydomain.com



回答2:


Assuming you have your virtual host's configuration file at /etc/apache2/sites-available, you must create a symlink to it at /etc/apache2/sites-enabled, like this:

ln -s /etc/apache2/sites-avaliable/mydomain.com /etc/apache2/sites-enabled/mydomain.com.conf

Notice that the extension of the symlink at sites-enabled is .conf. In my case, that was required as it's explained in the main configuration file /etc/apache2/apache2.conf:

# It is split into several files forming the configuration hierarchy outlined
# below, all located in the /etc/apache2/ directory:
#
#   /etc/apache2/
#   |-- apache2.conf
#   |   `--  ports.conf
#   |-- mods-enabled
#   |   |-- *.load
#   |   `-- *.conf
#   |-- conf-enabled
#   |   `-- *.conf
#   `-- sites-enabled
#       `-- *.conf

The last two lines explain that only files at sites-enabled with .conf extension are loaded.



来源:https://stackoverflow.com/questions/19150610/apache-showing-default-page-vhost-page

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