Apache 运行 2 laravel 应用程序使用 Location 标签

Apache run 2 laravel application using Location tag

我们能以某种方式做到这一点吗?我正在展示示例,但我们可以更改以下代码。

<Location />
    DocumentRoot /var/www/html/app1/public
</Location>

<Location /app2>
    DocumentRoot /var/www/html/app2/public
</Location>

不特定于 laravel。如果您希望 Apache 为 2 个不同的应用程序提供文件,请在 Apache 配置文件中设置虚拟主机

# Ensure that Apache listens on ports
Listen 80
Listen 81
Listen 82
Listen 83

<VirtualHost *:80>
    DocumentRoot "/www/example1"
    ServerName www.example.com

    # Other directives here
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/www/example2"
    ServerName www.example.org

    # Other directives here
</VirtualHost>

<VirtualHost *:81>
    DocumentRoot "/www/example3"

    # Other directives here
</VirtualHost>

<VirtualHost *:82>
    DocumentRoot "/www/example4"

    # Other directives here
</VirtualHost>

<VirtualHost *:83>
    DocumentRoot "/www/example5"

    # in the 'example5' folder place subfolders 'app1' and 'app2'
    # navigate in the browser to each app i.e. 127.0.0.1/example5/app1 and 127.0.0.1/example5/app2
    # Other directives here
</VirtualHost>

What i need ex: 192.168.1.23 will open app1 and 192.168.1.23/app2 will open app1

在这种情况下,您可以使用 Alias 指令,如下所示:

    <VirtualHost *:80>
        DocumentRoot /var/www/html/app1/public

        Alias /app2 /var/www/html/app2/public

        # add other directives here
    </VirtualHost>

这会将 /var/www/html/app2/public 的文件系统内容映射到 /app2,而默认的文档根目录 (/) 将是 /var/www/html/app1/public.

我建议你看看这里的文档,它对你的问题的不同解决方案给出了很好的解释:https://httpd.apache.org/docs/2.4/urlmapping.html