当子目录中存在Azure App Service的默认文档时,如何设置它? [英] How do I set the default document of an Azure App Service when it exists in a subdirectory?

查看:58
本文介绍了当子目录中存在Azure App Service的默认文档时,如何设置它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过发布管道从Azure DevOps部署Azure应用服务,该发布管道配置为在构建代理上执行Azure应用服务部署任务.部署任务的目标是我的App Service的根目录,因此它将部署在我的'\ site \ wwwroot \'文件夹中.

I am deploying an Azure App Service from Azure DevOps via a release pipeline that is configured to perform an Azure App Service Deploy task on my build agent. The deploy task targets the root of my App Service, so it will be deployed in my '\site\wwwroot\' folder.

我的项目是Laravel PHP Web应用程序,因此默认文档设置为'index.php'.我的应用程序已部署到"\ site \ wwwroot \",但是设置为默认文档的"index.php"文件的位置却位于"\ site \ wwwroot \"中.

My project is a Laravel PHP web application, so the default document is set to 'index.php'. My application is deployed to '\site\wwwroot\', but the location of my 'index.php' file that is set to the default document however is in '\site\wwwroot\'.

不是大问题,对吧?只需将应用程序目录设置为"\ site \ wwwroot \ public",该应用程序即可运行,因为它现在可以找到我的默认文档(index.php).除了一个问题.

Not a big problem, right? Just set the application directory to '\site\wwwroot\public' and the app works because it can now find my default document (index.php). Except there's one problem.

当Azure DevOps部署到Azure应用程序服务时,它将部署到您在Azure中设置的应用程序目录.由于现在我的根目录设置为"\ site \ wwwroot \ public",以解决查找默认文档的问题,因此AzureDevops会将后续版本部署到"\ site \ wwwroot \ public"文件夹.

When Azure DevOps deploys to an Azure App Service, it is going to deploy to the application directory that you set in Azure. Because my root is set to '\site\wwwroot\public' now to correct the issue with finding the default document, AzureDevops is deploying subsequent builds to the '\site\wwwroot\public' folder.

理想情况下,我想将"index.php"文件保留在"\ site \ wwwroot \ public"文件夹中,因为当我将其移至项目的根目录时会引起问题.我似乎无法弄清楚如何告诉Azure在我的公用文件夹中查找默认文档.我需要编写一个web.config并将其放置在我的项目根目录中以供IIS找到吗?

Ideally, I would like to keep my 'index.php' file within my '\site\wwwroot\public' folder, as it causes issues when I move it to the root of my project. I can't seem to figure out how to tell Azure to look in my public folder for the default document. Do I need to write a web.config and place it in my project root for IIS to find it?

更新:

我仍在尝试解决我遇到的这个问题.我无法配置Azure或Azure DevOps来区分应用程序部署到的目录和服务于应用程序的目录.

I'm still attempting to resolve this issue I am having. I am not able to configure Azure or Azure DevOps to differentiate between the directory that my app is deployed to, and the directory that my application is served from.

我不能简单地创建两个虚拟应用程序,因为这会将我的根目录暴露给该端点.我需要能够简单地指示Azure DevOps将应用程序放置在Web App上的位置.

I cannot simply create two virtual applications, as that would expose my root directory to that endpoint. I need to be able to simply instruct Azure DevOps where to place my application on the Web App.

推荐答案

  • 将server.php重命名为index.php
  • 将.htaccess文件从公用文件夹复制到根文件夹

    • Renaming the server.php to index.php
    • Copy the .htaccess from public folder to root folder

      更改.htaccess:

      Changing .htaccess :

      RewriteEngine On
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)/$ /$1 [L,R=301]
      
      RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^ index.php [L]
      
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_URI} !^/public/
      RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]
      

    • 更改功能/Illuminate/Foundation/helpers.php/asset()函数如下:

      change to function /Illuminate/Foundation/helpers.php/asset() function as follows:

      function asset($path, $secure = null)
      {
          return app('url')->asset("public/".$path, $secure);
      }
      

      这篇关于当子目录中存在Azure App Service的默认文档时,如何设置它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆