在 apache 虚拟主机中部署多个 Laravel 项目

时间:2021-02-20 05:50:43

标签: laravel apache deployment production

我有两个 Laravel 项目,我部署在 VPS 上,然后我在 /etc/apache2/sites-available 中为每个项目配置了 apache 虚拟主机。

示例:

project1.conf:

Listen 8999
NameVirtualHost *:8999
<VirtualHost *:8999>
    ServerName project1.test
    ServerAlias www.project1.test
    DocumentRoot "C:/laragon/www/data/project1/public"
    DirectoryIndex index.php   
    <Directory "C:/laragon/www/data/project1/public/">
         Options Indexes FollowSymLinks MultiViews ExecCGI
         AllowOverride All
         Order allow,deny
         Allow from all 
         Require all granted
    </Directory>
</VirtualHost>

project2.conf

Listen 8998
NameVirtualHost *:8998
<VirtualHost *:8998>
    ServerName project2.test
    ServerAlias www.project2.test
    DocumentRoot "C:/laragon/www/data/project2/public"
    DirectoryIndex index.php
   
    <Directory "C:/laragon/www/data/project2/public/">
         #Options Indexes FollowSymLinks MultiViews
         AllowOverride All
         #Order allow,deny
         Allow from all 
         Require all granted
    </Directory>
</VirtualHost>

在我的/windows/system32/drivers/etc/host中,我已经为每个项目制作了一个宿主。

但是我有一个问题,就是当我在浏览器中打开第一个项目并登录,然后同时打开第二个项目并登录,当第一个项目刷新时,它返回登录页。为什么会这样?

1 个答案:

答案 0 :(得分:0)

你可以尝试使用 Laravel Valet,而不是用困难的方式来做,它允许你将你的站点链接到一个域,如 localhost.test 和 localhost2.test。它负责所有虚拟主机配置。