【问题标题】:How to get a custom php application run from a subdirectory of a CI application on Google App Engine Standard?如何从 Google App Engine Standard 上的 CI 应用程序的子目录运行自定义 php 应用程序?
【发布时间】:2018-08-31 19:02:25
【问题描述】:

我对如何设置 app.yaml 以完成我的工作感到有些困惑。以前,我在其他地方运行相同的 codeigniter 应用程序,/support 子目录为自定义 php 支持台应用程序提供服务。它没有问题。好的 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 .. 现在支持根目录和 1 级子目录中的所有 php 脚本都可以工作

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

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

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

【问题讨论】:

  • 再次,您的嵌套错误。 URL 是相对于 app.yaml 文件的,因此不要在脚本路径中包含 support/。正则表达式通配符方法为您处理所有嵌套。只需在答案中使用:- url: /(.+)\.php script: \1.php
  • 等等!所以您编辑了问题并将您的app.yaml 移动到某个地方?现在在哪里?
  • 对于从 /support/.. 运行的应用程序没有单独的 app.yaml。你看到的是一个很长的故事。 app.yaml 是它应该在的地方!在/
  • 老兄一定有一些误解.. 我的 codeigniter 应用程序位于 / 并且名为“Hesk”的自定义基于 php 的支持台运行在 /support/
  • /(.+)\.php script: \1.php 只会处理直接调用的位于/ 的php 脚本,它也不会将/ 映射到/index.php

标签: php codeigniter google-app-engine google-cloud-platform google-app-engine-php


【解决方案1】:

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

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

注意:您的app.yamlindex.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

【讨论】:

  • 您帮助我意识到我忘记在脚本值上添加支持目录。但它实际上不起作用 - url: /support/ script: support/index.php 帮助我获得支持的根,但每当我使用 support/index.php 或其他一些 php 文件时,我都会得到 404。我还需要让所有静态文件也能正常工作。你知道如何获得它们吗?
  • 查看更新。您的文件嵌套在目录中的方式有​​问题。
  • 我的问题不是如何定义静态目录..我知道怎么做..反正现在看看我的更新
  • 你说,“还需要定义静态文件。你可以看到它们分散在各处”,所以我为你解决了这个问题
  • 伙计,它是一个 3rd 方应用程序.. 你认为我想把所有的静态文件收集到整个目录和子目录 n 把它们放在一个文件夹中!?我想你错过了- url: /assets static_dir: assets!我已经认识那个人了!
【解决方案2】:

解决方案: 谢谢GAEfan ..我有点混合了你的想法,最后这些是需要的处理程序。现在运行完美!

#for all the static files residing at support root or at any other level
- url: /support/(.*\.(htm$|css$|js$|ico$|jpg$|png$|gif$))$
  static_files: support/\1
  upload: support/.*\.(htm$|css$|js$|ico$|jpg$|png$|gif$)$
  application_readable: true

#for all the php files running at support root or at any other level
- url: /support/(.+)\.php
  script: support/\1.php

#for using index.php at support root or at any other level
- url: /support/(.*)
  script: support/\1/index.php

P.S : 下面的处理程序可以从任何其他级别运行 index.php 但不支持 root

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

【讨论】:

    猜你喜欢
    • 2013-12-20
    • 2019-07-18
    • 1970-01-01
    • 2011-03-08
    • 1970-01-01
    • 2016-03-11
    • 1970-01-01
    • 2016-12-28
    • 1970-01-01
    相关资源
    最近更新 更多