无法访问本地网页(错误:无法解析主机)

DR.*_*H.d 3 server apache2

这正是我现在所设置的:

cd /var/www
mkdir -p 测试
cd /var/www/测试
须藤纳米索引.html
cd /etc/apache2/sites-available cd /etc/apache2/sites-available
须藤纳米测试.conf
<VirtualHost *:80>
    ServerName localhost223.com
    DocumentRoot /var/www/test
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
$sudo a2ensite test.conf
$sudo 服务 apache2 重新加载

我可以像这样访问我的页面:file:///var/www/test/index.html在网络浏览器中。

<html>
    <h1>
         here
    </h1>
</html>
Run Code Online (Sandbox Code Playgroud)

但我无法访问:http://localhost223.com

我收到错误:Could not resolve host

如何解决这个问题?

pa4*_*080 5

正如@George所说,虽然没有FQDN指向您服务器的 IP,但您需要通过文件中的下一行将域名与环回接口-绑定:127.0.0.1/etc/hosts

127.0.0.1 localhost223.com
Run Code Online (Sandbox Code Playgroud)

/etc/apache2/sites-available/test.conf然后按如下方式编辑:

<VirtualHost *:80>

        ServerName localhost223.com
        DocumentRoot /var/www/test

        <Directory /var/www/test>
                Options None FollowSymLinks
                # Enable .htaccess Overrides:
                AllowOverride All
                DirectoryIndex index.html index.php
                Order allow,deny
                Allow from all
                Require all granted
        </Directory>

</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

不要忘记sudo a2ensite test.conf,然后重新启动网络服务器:

  • 乌班图14.04:sudo service apache2 restart

  • 乌班图16.04:sudo systemctl restart apache2.service

尝试通过浏览器访问您的页面。