问题描述

参考官方文档部署 PHP Laravel 项目到App Service for Linux环境中,但是访问应用时候遇见了500 Server Error 错误。

从部署的日志中,可以明确看出部署是成功的,那么为什么启动页面不成功呢?

问题分析

Laravel 应用程序生命周期在 public 目录中开始,而不是在应用程序的根目录(wwwroot)中开始。在Azure App Service中,所有项目的默认根目录都是wwwroot。

但是可以使用 .htaccess 来重写所有请求,使之指向 /public 而不是根目录。 在存储库根目录中,已针对此目的添加了 .htaccess。 有了它即可部署 Laravel 应用程序。

.htaccess文件(或者"分布式配置文件"),全称是Hypertext Access(超文本入口)。提供了针对目录改变配置的方法, 即,在一个特定的文档目录中放置一个包含一个或多个指令的文件, 以作用于此目录及其所有子目录。

.htaccess 详解:https://www.cnblogs.com/adforce/archive/2012/11/23/2784664.html

.htaccess 使用介绍:https://www.cnblogs.com/gyrgyr/p/10773118.html

问题解决

更改站点根路径,所选的 Web 框架可能使用子目录作为站点根路径。 例如Laravel 使用 public/ 子目录作为站点根路径。

应用服务的默认 PHP 映像使用 Apache,不允许为应用自定义站点根路径。 若要避开此限制,请将 .htaccess 文件添加到存储库根路径,并包含以下内容:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} ^(.*)
RewriteRule ^(.*)$ /public/$1 [NC,L,QSA]
</IfModule>

以上为修改Laravel项目的根目录到 wwwroot/public中。如要指定到具体的启动页面,可以在public中加入页面名称,如 index.php。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)
RewriteRule ^(.*)$ public/index.php?/$1 [L]
</IfModule>

参考资料

App Service PHP laravel 更改站点根路径: https://docs.azure.cn/zh-cn/app-service/configure-language-php?pivots=platform-linux#change-site-root

在 Azure 应用服务中生成 PHP 和 MySQL 应用: https://docs.azure.cn/zh-cn/app-service/tutorial-php-mysql-app?pivots=platform-linux

Laravel Lifecycle Overview: https://laravel.com/docs/5.4/lifecycle

First Things

The entry point for all requests to a Laravel application is the public/index.php file. All requests are directed to this file by your web server (Apache / Nginx) configuration. The index.php file doesn't contain much code. Rather, it is simply a starting point for loading the rest of the framework.

Apache's mod_rewrite: http://www.datakoncepts.com/seo or https://httpd.apache.org/docs/current/mod/mod_rewrite.html

The mod_rewrite module uses a rule-based rewriting engine, based on a PCRE regular-expression parser, to rewrite requested URLs on the fly. By default, mod_rewrite maps a URL to a filesystem path. However, it can also be used to redirect one URL to another URL, or to invoke an internal proxy fetch.

mod_rewrite provides a flexible and powerful way to manipulate URLs using an unlimited number of rules. Each rule can have an unlimited number of attached rule conditions, to allow you to rewrite URL based on server variables, environment variables, HTTP headers, or time stamps.

mod_rewrite operates on the full URL path, including the path-info section. A rewrite rule can be invoked in httpd.conf or in .htaccess. The path generated by a rewrite rule can include a query string, or can lead to internal sub-processing, external request redirection, or internal proxy throughput.

最新文章

  1. php常用函数
  2. python——连接Oracle数据库
  3. AngularJS的$watch用法
  4. Eclipse调试按钮消失问题
  5. Objective-C学习笔记_Xcode模拟命令行填入参数执行
  6. java中的包装类与装箱拆箱定义
  7. hdu 4662 MU Puzzle
  8. angularjs学习笔记三——directive
  9. ECharts JavaScript图表库 ECharts
  10. cocos2dx三种定时器使用
  11. Tomcat过滤器模拟
  12. 微信小程序之----加载中提示框loading
  13. HTML中块元素与内联元素的概念
  14. NPOI 修改指定单元格字体颜色
  15. ubuntu18.04虚拟机安装docker
  16. 管道流_PipedInputStream与PipedOutputStream
  17. C# winform C/S WebBrowser 微信第三方登录
  18. mybatis启动报错Mapped Statements collection already contains value for com.autoyol.mapper.trans.TransDispatchingMapper解决
  19. MongoDB的”存储过程“
  20. vue 设置代理后 后端获取不到登录的session处理方法

热门文章

  1. 【原创】利用动态二进制加密实现新型一句话木马之PHP篇
  2. 新版数据库分页方法(Sql server2012)
  3. Java入门姿势【面向对象3】构造方法及其重载_方法的调用
  4. 题解 Game
  5. 题解 d
  6. Spring-boot注入配置为java静态属性
  7. Linux 安装配置 NET模式网络环境配置
  8. 默认标签的解析过程(三)parseDefaultElement
  9. 高德渲染网关Go语言重构实践
  10. go语言内存对齐