4

Google App Engine、PHP、Mimetype、app.yaml、static_dir、脚本、static_files

当我部署我的网站时,PHP 文件导致错误消息:

无法猜测 mimetype

这是appl.yaml配置文件:

application: applicationname
version: 1
runtime: php
api_version: 1
threadsafe: true

handlers:

- url: /
  script: index.php

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

- url: /Client_Pages
  static_dir: Client_Pages

导致错误的文件未加载到已部署的网站中。相同的文件可以Google App Engine Launcher在我的计算机上完美运行。

根目录下的index.php文件不会报错,在部署的网站上运行。

似乎我部署的网站将加载PHP文件静态html文件,但不能同时加载两者?我在同一个文件夹中同时拥有PHP和文件。我想知道这是否会导致问题,但我找不到任何说明我不能将它们放在同一个文件夹中的文档。HTMLClient_Pages

我尝试在PHP文件中明确引用app.yaml文件,这会导致PHP文件运行,但HTML文件不会加载。

application: yardsalesuperhighway
version: 1
runtime: php
api_version: 1
threadsafe: true

handlers:

- url: /Client_Pages/Offered_Menu.php
  script: Client_Pages/Offered_Menu.php

- url: /Client_Pages/InputForm.php
  script: Client_Pages/InputForm.php

- url: /Client_Pages/WantedPage.php
  script: Client_Pages/WantedPage.php

- url: /Client_Pages
  static_dir: Client_Pages
4

3 回答 3

2

如果没有特定指令,您的应用程序无法访问存储在 static_dir 中的文件。

从文档 -

应用程序可读

可选的。默认情况下,在静态文件处理程序中声明的文件作为静态数据上传并仅提供给最终用户,应用程序无法读取它们。如果此字段设置为 true,则文件也会作为代码数据上传,以便您的应用程序可以读取它们。

我不确定 app.yaml 中的处理程序可以与静态目录重叠。这不是我测试过的东西,如果不可能,我不会感到惊讶。应用程序代码被上传到 appengine 基础架构中的不同服务。

于 2014-03-20T03:17:35.633 回答
2

不确定帖子是否仍然打开。我似乎遇到了类似的问题,这对我有用。我所做的是添加application_readable: truemime_type: text/html在我保存 php 文件的目录下。所以也许你app.yaml应该看起来像:

application: yardsalesuperhighway
version: 1
runtime: php
api_version: 1
threadsafe: true

handlers:

- url: /Client_Pages/Offered_Menu.php
  script: Client_Pages/Offered_Menu.php

- url: /Client_Pages/InputForm.php
  script: Client_Pages/InputForm.php

- url: /Client_Pages/WantedPage.php
  script: Client_Pages/WantedPage.php

- url: /Client_Pages
  application_readable: true # allow for php scripts in the dir to be executable by the application (as specified in the documentation provided by Tim)
  mime_type: text/html # assuming the php scripts will be echoing something, have what the echo as html (I got the mime types from http://www.iana.org/assignments/media-types/media-types.xhtml)
  static_dir: Client_Pages

我让我的代码可以使用它,它甚至可以使用与 php 脚本能够加载的同一目录中的 HTML 文件。

于 2014-12-22T02:39:39.223 回答
1

不要使用 static_dir,而是考虑使用 static_files 仅上传您想要静态的文件:

handlers:

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

- url: /Client_Pages/(.*\.html)
  static_files: Client_Pages/\1
  upload: Client_Pages/.*\.html

- url: /
  script: index.php
于 2014-12-22T07:12:42.983 回答