首页 > 解决方案 > 如何从 Google App Engine Standard 上的 CI 应用程序的子目录运行自定义 php 应用程序?

问题描述

我对如何设置 app.yaml 以完成我的工作感到有些困惑。以前,我在其他地方运行了相同的 codeigniter 应用程序,其/support子目录为自定义 php 支持台应用程序提供服务。它没有问题。Good ol' apache 服务它没有任何问题。

现在我想在 GAE 上做同样的事情!这是我的 app.yaml

application: <NAME>
version: 1
runtime: php55
api_version: 1
threadsafe: yes

handlers:

- url: /assets
  static_dir: assets

- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: /support/.*
  script: index.php

- url: /.*
  script: index.php
  secure: always

只是为了确保在有人为我提供解决方案后我得到正确路由的所有文件。这是支持台的目录结构(称为 hesk)-

在此处输入图像描述

我需要一个带有通配符的解决方案,以便/support与子文件夹和所有内容完美配合..还需要定义静态文件。正如你所看到的,它们散落在各处……一点也不方便,但就是这样!我不擅长正则表达式。所以请怜悯我。

更新: 我添加了更新的 app.yaml .. 现在支持根目录和第一级子目录中的所有 php 脚本都可以工作

- url: /support/(.*)/(.*)\.php$
  script: support/\1/\2.php

- url: /support/(.*)\.php$
  script: support/\1.php

但问题是这个东西有很多子文件夹。请参阅 support/inc 文件夹下方的此快照。如何处理?我是否必须为所有可能的子目录级别手动放置一个 url-script 对?这太令人沮丧了!

在此处输入图像描述

标签: phpcodeignitergoogle-app-enginegoogle-cloud-platformgoogle-app-engine-php

解决方案


您将每个呼叫发送- url: /support/.*index.php。你想要的是一个正则表达式发送到正确的脚本:

- url: /support/(.+).php
  script: support/\1.php

注意:您的app.yamlandindex.php位于support目录内。您将需要app.yaml在根目录下,否则您将无法访问支持目录之外的文件。是support这个应用程序的根吗?

记住:url 是相对于app.yaml文件的

对于根级别的文件,您将使用:

- url: /(.+).php
  script: \1.php

您需要将静态文件放在静态目录中,然后使用:

- url: /static
  static_dir: static

并使用例如访问文件:/static/hesk_javascript.js

更新 2 使用正则表达式处理静态文件:

- url: /support/(.*\.(ico|jpg|jpeg|png|gif|woff|ttf|otf|eot|svg))$
  static_files: support/\1
  upload: support/.*\.(ico|jpg|jpeg|png|gif|woff|ttf|otf|eot|svg)$
  application_readable: true

推荐阅读