【问题标题】:configure virtual hosts in azure ubuntu to run multiple laravel applications在 azure ubuntu 中配置虚拟主机以运行多个 laravel 应用程序
【发布时间】:2016-09-27 07:51:24
【问题描述】:

我在 /home/azureuser 目录下创建了 2 个 laravel 应用程序。

我想在单个 ubuntu 虚拟机上运行多个 laravel 应用程序。我尝试配置虚拟主机但无法使其工作。

以下是/etc/apache2/sites-enabled/000-default.conf的内容

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName apitesting.cloudapp.net/demo
        DocumentRoot /home/azureuser/demoapp/public
        <Directory /home/azureuser/demoapp/public>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Require all granted
        </Directory>
        SetEnv APPLICATION_ENV dev
        LogLevel warn
</VirtualHost>

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName apitesting.cloudapp.net/quiz
        DocumentRoot /home/azureuser/quizapp/public
        <Directory /home/azureuser/quizapp/public>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Require all granted
        </Directory>
        SetEnv APPLICATION_ENV dev
        LogLevel warn
</VirtualHost>

不确定以上是否正确。

【问题讨论】:

    标签: php azure ubuntu virtualhost


    【解决方案1】:

    似乎我们无法在 URL 中使用子路径参数设置 ServerName。根据您的要求,您可以利用 rewrite mod。

    首先,通过命令:sudo a2enmod rewrite 安装 apache rewrite mod,然后通过:sudo service apache2 restart 重新启动 apache。

    之后,修改配置文件/etc/apache2/sites-enabled/000-default.conf,将目录配置为你的应用程序的父文件夹:

    ... 
    DocumentRoot /home/azureuser
    ServerName apitesting.cloudapp.net
    <Directory /home/azureuser>
                    Options Indexes FollowSymLinks MultiViews
                    AllowOverride All
                    Require all granted
    </Directory>
    ...
    

    然后在你的应用根目录下创建一个名为.htaccess的文件,将传入的请求重定向到你的public文件夹,内容如下:

    <IfModule mod_rewrite.c>
       RewriteEngine On
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteRule ^(.*)$ public/$1 [L]
    </IfModule>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-29
      • 1970-01-01
      • 2011-11-20
      • 2014-10-05
      • 1970-01-01
      • 2015-01-02
      • 2022-10-15
      相关资源
      最近更新 更多