首页 > 解决方案 > 带有 Laravel 和 Apache 的虚拟主机,无法将 ip 设置为网站名称

问题描述

我想将我的网站的 ip 设置为按字母顺序排列的名称(即http://54.183.131.205http://www.rblog.com)。虽然我已经在 /etc/apache2/sites-available 中配置了我的 rblog.com.conf,启用它并重新加载了我的 apache 服务器,然后添加到我的 /etc/hosts 文件 54.183.131.205 www.rblog.com(之间的标签ip 和网站名称),在我的浏览器中输入 www.rblog.com 不会将我重定向到我的 index.php 文件。但是,请注意,当我在浏览器中输入 IP 地址时,它会将我带到我的 index.php 文件(我相信这意味着我的 rblog.com.conf 文件是正确的?)。

<VirtualHost *:80>
    ServerAdmin webmaster@rblog.com
    ServerName www.rblog.com
    ServerAlias www.rblog.com
    DocumentRoot /var/www/html/rblog/public

    <Directory /var/www/html/rblog/public>
       Options -Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted
        <FilesMatch \.php$>
        </FilesMatch>
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

标签: laravelapache

解决方案


<VirtualHost *:80>
    ServerAdmin webmaster@rblog.com
    ServerName rblog.com
    ServerAlias www.rblog.com
    DocumentRoot /var/www/html/rblog/public
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

我们可以使用 a2ensite 工具来启用我们的每个站点,如下所示:

sudo a2ensite example.com.conf
sudo a2ensite test.com.conf

完成后,您需要重新启动 Apache 以使这些更改生效:

sudo service apache2 restart

/etc/hosts 文件

54.183.131.205 rblog.com

推荐阅读