ubuntu - 虚拟主机 UBUNTU 显示无法访问此站点

标签 ubuntu virtualhost ubuntu-12.04

我在 Ubuntu 20.04.3 LTS 上配置了虚拟主机,但它不工作。
首先使用以下方法创建目录:

sudo mkdir -p /var/www/domain1.com/public_html
然后在其中创建 index.html 文件:
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Welcome to domain1.com</title>
  </head>
  <body>
    <h1>Success! domain1.com home page!</h1>
  </body>
</html>
为了避免权限问题,我运行了这个命令:
sudo chown -R www-data: /var/www/domain1.com
然后在/etc/apache2/sites-available 我创建了一个配置文件:
/etc/apache2/sites-available/domain1.com.conf
并将这段代码放入其中
<VirtualHost *:80>
    ServerName domain1.com
    ServerAlias www.domain1.com
    ServerAdmin webmaster@domain1.com
    DocumentRoot /var/www/domain1.com/public_html

    <Directory /var/www/domain1.com/public_html>
        Options -Indexes +FollowSymLinks
        AllowOverride All
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/domain1.com-error.log
    CustomLog ${APACHE_LOG_DIR}/domain1.com-access.log combined
</VirtualHost>
然后运行这个命令:
sudo a2ensite domain1.com
然后使用命令重新启动apache:
sudo systemctl restart apache2
然后测试配置:
sudo apachectl configtest
输出为 语法确定
但是当我在浏览器中访问 domain1.com 时,得到 "This site can’t be reached"错误。

最佳答案

您已将 Apache 配置为特殊情况,它接收到的任何请求 domain1.com你没有:

  • 注册 domain1.com
  • 使用 A 记录配置 DNS 服务器,将 domain1.com 指向 Apache 正在监听的 IP 地址

  • (或者使用类似 hosts 的文件进行本地破解)。

    关于ubuntu - 虚拟主机 UBUNTU 显示无法访问此站点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70608154/

    相关文章:

    node.js - 错误此版本的 Node/NAN/v8 需要 C++11 编译器

    parsing - Yacc 和 Lex "syntax error"

    apache - .htaccess 不被 apache 读取

    linux - AWS-EC2,如何用一个实例设置多个公共(public)站点?

    subdomain - 在 CentOS 6.2 上的 apache 中创建子域/虚拟主机

    laravel - Apache 2.4 具有不同别名和路径的多个站点

    php - 在终端中执行 php 脚本出现权限被拒绝错误

    python - execsql 1.72 无法安装 Python

    linux - 通过在 iptables (Ubuntu) 中添加规则来打开端口 443

    c - 源文件找不到头文件