我的 Apache 配置有什么问题?

我的 Apache 配置有什么问题?

我的站点中有一个 000-default.conf(它是空的):

 <VirtualHost *:80>

 </VirtualHost>

以及另一个我已经启用的 .conf 文件(在 sites-available 目录中)。这个:

    <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 asd.com
            ServerAlias www.asd.com

            ServerAdmin [email protected]
            DocumentRoot /srv/rypock

            <Directory /srv/rypock/>
                    AllowOverride All
                    Options Indexes FollowSymLinks
                    Require all granted
            </Directory>

            # 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 /srv/asd-log/error.log
            CustomLog /srv/asd-log/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>

但是,当我访问 asd.com 时,我的网站无法访问。我已经重启了服务器。问题出在哪里?

答案1

您需要确保您的网站已启用。您还需要确保asd.com指向您的网站。

使用以下命令启用您的站点并重新启动 Apache(替换another为文件名):

sudo a2ensite another.conf
sudo apache2ctl restart

如果该站点位于您的本地计算机上,您可以编辑该/etc/hosts文件并向其中添加以下行(如果该站点位于不同的计算机上,则替换 IP):

127.0.1.1       asd.com

如果这是一个具有真实 DNS 条目的实时站点,您可能需要等待一段时间,直到 DNS 条目传播并更新,以防您从旧值更新它。

注意:正如@Mark 所建议的那样他的评论,您可以禁用默认虚拟主机与a2dissite

sudo a2dissite 000-default

相关内容