Apache vhost 配置

Apache vhost 配置

你好,我尝试在我的服务器上配置虚拟主机,但是它不起作用。

当尝试访问时,它变为默认状态......

这是我的基本配置。

在我的服务器上:

/var/www/html/blentico.com/public_html/index.php (和 Wordpress 包)

/etc/apache2/sites-available/blentico.com.conf

这是 blentico.com.conf 的内容

<VirtualHost *:80>
ServerAdmin [email protected]
ServerName blentico.com
Serveralias www.blentico.com
DocumentRoot /var/www/html/blentico.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

然后我运行命令:

a2ensite blentico.com.conf

/var/www 内的所有文件/目录都具有用户/组 root 和 755 权限

好的,所以,根据我读过的所有文档,我认为这是可以的,但是当我尝试访问 www.blentico.com 时,它直接转到位于 /var/www/html/index.php 的 index.php 文件,而不是 /var/www/html/blentico.com/public_html,正如我在 blentico.com.conf 文件中指出的那样。

希望你能帮我。

答案1

至少你需要用<VirtualHost></VirtualHost>标签包装你的配置。否则我想它会被合并到默认配置中。参见https://httpd.apache.org/docs/2.4/vhosts/有关设置虚拟主机的更多信息。

答案2

完毕!

我的默认配置(000-默认.conf) 处于活动状态,没有 ServerName,所以总是以这个 DocumentRoot(000-default.conf 文件的 DocumentRoot)结尾,对吗?我认为是的,因为当我停用此配置时a2dissite 000-默认重新启动 apache,我的配置开始工作。我还对我的配置文件做了一些修改,尽管这对我的第一个问题没有任何影响。无论如何,我在下面展示它

<VirtualHost *:80>

    ServerAdmin [email protected]
    ServerName blentico.com
    Serveralias www.blentico.com
    DocumentRoot /var/www/html/blentico.com/public_html

    ErrorLog /var/log/apache2/blentico.com-error.log
    CustomLog /var/log/apache2/blentico.com-access.log combined

    <Directory /var/www/html/blentico.com/public_html>
            Order allow,deny
            allow from all
    </Directory>

相关内容