使用虚拟主机时“无法访问此站点”
我正在尝试设置Apache2服务器。 安装和配置似乎进展顺利,但当我尝试转到我的自定义Web URL时,我收到“无法访问此站点”错误。 我尝试通过此答案设置配置文件 – 尝试访问浏览器中的Apache 2.4.7 Web服务器时出现Forbidden 403错误 。
我的hosts文件如下所示:
127.0.0.1 localhost 127.0.0.1 justtestingthis 127.0.1.1 Hacker # The following lines are desirable for IPv6 capable hosts ...
我的apache2/sites-available/http.justtestingthis.conf
文件如下所示:
ServerAdmin webmaster@example.com ServerName justtestingthis.com ServerAlias www.justtestingthis.com DocumentRoot /home/donatas/Desktop/Projects/justtestingthis/dist/src DirectoryIndex index.php ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # Allow .htaccess AllowOverride All Allow from All
我还使用sudo a2ensite http.justtestingthis.conf
在apache2/sites-enabled
创建了这个文件的链接。
当我通过输入http:// localhost访问网站时,我的网站被成功找到,但是当我试图通过justtestingthis.com或www.justtestingthis.com访问它时,我得到了“这个网站”无法达到错误“……
我究竟做错了什么?
您的浏览器无法打开justtestingthis.com
页面的原因是没有别名指向它应该去的位置。 你的/etc/hosts
文件只有127.0.0.1 justtestingthis
,这就是名字。 浏览器不知道.com
的名称在哪里,因为它没有指定。
要解决此问题,请将/etc/hosts
的行更改为:
127.0.0.1 www.justtestingthis.com
现在,这应该将justtestingthis.com
别名为localhost
或者将您的Web浏览器中的127.0.0.1
别名为Apache页面。 它也将在没有www的justtestingthis.com
打开。
希望这可以帮助!