我能’;我不能在Apache中配置虚拟主机,尽管我会按照说明进行所有操作。原因是什么?

我能’;我不能在Apache中配置虚拟主机,尽管我会按照说明进行所有操作。原因是什么?,apache,ubuntu-18.04,Apache,Ubuntu 18.04,我不能在Apache中配置虚拟主机,尽管我是根据。原因是什么? 我试图在Apache中配置虚拟主机,但失败了。我毫无问题地执行了指令,但这对我不起作用 Ubunttu 18.04。根目录是/var/www/html 有一个index.html,可以从网络访问。 现在,如果您只是在浏览器中键入站点的地址,那么它仍然会显示,/var/www/html/index.php,而不是来自虚拟主机的index.html。也就是说,事实证明虚拟主机根本不工作 我做了以下工作: sudo mkdir -p /v

我不能在Apache中配置虚拟主机,尽管我是根据。原因是什么? 我试图在Apache中配置虚拟主机,但失败了。我毫无问题地执行了指令,但这对我不起作用

Ubunttu 18.04。根目录是/var/www/html

有一个index.html,可以从网络访问。 现在,如果您只是在浏览器中键入站点的地址,那么它仍然会显示,/var/www/html/index.php,而不是来自虚拟主机的index.html。也就是说,事实证明虚拟主机根本不工作

我做了以下工作:

sudo mkdir -p /var/www/xxxxxx.xx/html
sudo chown -R $USER:$USER /var/www/xxxxxx.xx/html
sudo chmod -R 755 /var/www/xxxxxx.xx

nano /var/www/xxxxxx.xx/html/index.html
在这里添加了页面代码

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/xxxxxx.xx.conf
sudo nano /etc/apache2/sites-available/xxxxxx.xx.conf
我插入xxxxxx.xx.conf:

<VirtualHost *:80>
  ServerAdmin host1@gmail.com
  ServerName xxxxxx.xx
  ServerAlias www.xxxxxx.xx
  DocumentRoot /var/www/xxxxxx.xx/html
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined
  DirectoryIndex index.php
</VirtualHost>

sudo a2ensite xxxxxx.xx.conf
sudo a2dissite 000-default.conf
sudo systemctl restart apache2

怎么了?我是第一次安装Apache,但根据说明,在执行过程中没有出现错误。

只需做以下更改,添加index.html而不是index.php

<VirtualHost *:80>
      ServerAdmin host1@gmail.com
      ServerName xxxxxx.xx
      ServerAlias www.xxxxxx.xx
      DocumentRoot /var/www/xxxxxx.xx/html
      ErrorLog ${APACHE_LOG_DIR}/error.log
      CustomLog ${APACHE_LOG_DIR}/access.log combined
      DirectoryIndex index.html 
    </VirtualHost>

服务器管理员host1@gmail.com
服务器名xxxxxx.xx
服务器别名www.xxxxxx.xx
DocumentRoot/var/www/xxxxxx.xx/html
ErrorLog${APACHE_LOG_DIR}/error.LOG
CustomLog${APACHE\u LOG\u DIR}/access.LOG组合
DirectoryIndex.html

非常感谢!我已经把头撞在墙上了。你说得对,原因是文件扩展名。我将.php改为.html,效果很好。
<VirtualHost *:80>
      ServerAdmin host1@gmail.com
      ServerName xxxxxx.xx
      ServerAlias www.xxxxxx.xx
      DocumentRoot /var/www/xxxxxx.xx/html
      ErrorLog ${APACHE_LOG_DIR}/error.log
      CustomLog ${APACHE_LOG_DIR}/access.log combined
      DirectoryIndex index.html 
    </VirtualHost>