【Azure 应用服务】App Service For Linux 部署PHP Laravel 项目,如何修改首页路径为 wwwroot\public\index.php
问题描述
参考官方文档部署 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.phpfile. All requests are directed to this file by your web server (Apache / Nginx) configuration. Theindex.phpfile 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.
【Azure 应用服务】App Service For Linux 部署PHP Laravel 项目,如何修改首页路径为 wwwroot\public\index.php的更多相关文章
- 【Azure 应用服务】App Service For Linux 部署Java Spring Boot应用后,查看日志文件时的疑惑
编写Java Spring Boot应用,通过配置logging.path路径把日志输出在指定的文件夹中. 第一步:通过VS Code创建一个空的Spring Boot项目 第二步:在applicat ...
- 【应用服务 App Service】快速获取DUMP文件(App Service for Windows(.NET/.NET Core))
问题情形 当应用在Azure 应用服务App Service中运行时,有时候出现CPU,Memory很高,但是没有明显的5XX错误和异常日志,有时就是有异常但是也不能明确的指出具体的代码错误.当面临这 ...
- 【Azure 应用服务】部署Jar到App Service for Linux,因启动命令路径配置错误而引起:( Application Error 问题
问题描述 App Service for Linux 资源创建完成后,通过FTP方式把 .jar包(logdemo.jar)包上传到 /site/wwwroot/ 文件夹后,在App Service的 ...
- 【Azure 应用服务】PHP应用部署在App Service for Linux环境中,上传文件大于1MB时,遇见了413 Request Entity Too Large 错误的解决方法
问题描述 在PHP项目部署在App Service后,上传文件如果大于1MB就会遇见 413 Request Entity Too Large 的问题. 问题解决 目前这个问题,首先需要分析应用所在的 ...
- 【Azure 应用服务】Azure App Service For Linux 上实现 Python Flask Web Socket 项目 Http/Https
问题描述 在上篇博文"[Azure 应用服务]App Service for Linux 中实现 WebSocket 功能 (Python SocketIO)"中,实现了通过 HT ...
- 【Azure 应用服务】App Service For Linux 如何在 Web 应用实例上住抓取网络日志
问题描述 在App Service For Windows的环境中,我们可以通过ArmClient 工具发送POST请求在Web应用的实例中抓取网络日志,但是在App Service For Linu ...
- 【Azure 应用服务】App Service for Linux 中实现 WebSocket 功能 (Python SocketIO)
问题描述 使用 python websockets 模块作为Socket的服务端,发布到App Service for Linux环境后,发现Docker Container无法启动.错误消息为: 2 ...
- 【Azure 应用服务】Python flask 应用部署在Aure App Service 遇见的 3 个问题
在App Service(Windows)中部署Flask应用时的注意事项: ● 添加Python扩展插件,Python 3.6.4 x64: ●● 配置 FastCGI 处理程序,添加Web.con ...
- 【应用服务 App Service】App Service使用Git部署时,遇见500错误
问题描述 Azure App Service在部署的时候支持多种方式,如Zip,VS 2019, VS Code,或者是Git部署,当使用Git部署遇见500错误时,可以通过其他的部署方式来验证是否也 ...
随机推荐
- Golang语言系列-04-运算符
运算符 Go语言内置的运算符有 算术运算符 关系运算符 逻辑运算符 位运算符 赋值运算符 算术运算符 package main import "fmt" func main() { ...
- Sqli-Labs less13-16
less-13 首先,输入用户名和密码,发现只有成功和失败两种显示,没有数据回显: 然后我们抓包拿到数据: 我们通过上述观察,已经知道这是典型的盲注,可以采用布尔盲注或者时间盲注. 构造注入语句:un ...
- kivy之TextInput属性实操练习
TextInput属性比较多,常用在页面设计上的属性做了实操练习,便于很直观的了解学习本部件.并将其中一个输入提示的属性在实操源码里单独建立了一个功能进行演示. 主程序文件main.py我就不贴出来了 ...
- Spring中的@Transactional必须要了解的概念
spring中的@Transactional基于动态代理的机制,提供了一种透明的事务管理机制,方便快捷解决在开发中碰到的问题. 一般使用是通过如下代码对方法或接口或类注释: 1 @Transactio ...
- tcphdr结构
包含在/usr/src/linux/include/linux/tcp.h 1 struct tcphdr { 2 __be16 source; 3 __be16 dest; 4 __be32 seq ...
- IDEA debug启动的时候需要等半个小时甚至更长时间
debug启动的时候需要等半个小时甚至更长时间 突然有一天发现debug启动不起来了, 在debug时,项目一直会出现 Connected to the VM ,address: 其实这不是debug ...
- opengl中标准矩形像素点手动网格化为三角形条带的实现
这里以一张矩形图片为例进行说明: 一张图片的像素点是孤立的,导入opengl中进行绘制出来,看起来没问题,但是当我们放大图片时候,显示的就是一个个孤立的点,而没有像看图软件放大图片那样看起来还是连续的 ...
- 如何实现LRU缓存
大家好,我是程序员学长,今天我们来聊一聊LRU缓存问题. Tips: LRU在计算机软件中无处不在,希望大家一定要了解透彻. 问题描述 设计LRU(最近最少使用)缓存结构,该结构在构造时确定大小,假设 ...
- 操作系统IO之零拷贝技术
磁盘可以说是计算机系统最慢的硬件之一,读写速度相差内存 10 倍以上,所以针对优化磁盘的技术非常的多,比如零拷贝.直接 I/O.异步 I/O 等等,这些优化的目的就是为了提高系统的吞吐量,另外操作系统 ...
- shell循环语句until
until 条件 do 执行命令 done until 循环与 while 循环在处理方式上刚好相反. 当条件成立的时候,停止循环.