0

所有其他静态文件在域中正常使用。

似乎 PHP 文件没有运行;当我不尝试将其作为脚本运行(而只是将其作为静态文件上传)时,它可以正常工作;当 jQuery 调用它时返回纯文本 - 所以它绝对不是文件路径问题。

但是一旦我将它列为 yaml 中的 php 文件并期望 jQuery 获取“你好,世界!” 它在 Firefox 网络监视器中返回 404,并且在控制台中没有响应。

关于在 App Engine Standard 上运行单独的服务器端 php 脚本,我有什么遗漏吗?

应用程序.yaml

runtime: php55
api_version: 1
threadsafe: true

handlers:
# Serve php scripts another way.
- url: /scripts/elastic.php
  script: scripts/elastic.php

# Handle the main page by serving the index page.
# Note the $ to specify the end of the path, since app.yaml does prefix matching.
- url: /$
  static_files: index.html
  upload: index.html


# Handle folder urls by serving the index.html page inside.
- url: /(.*)/$
  static_files: \1/index.html
  upload: .*/index.html

# Handle nearly every other file by just serving it.
- url: /(.+)
  static_files: \1
  upload: (.*)

弹性.php

<?php
return 'Hello, world!'
?>

script.js(在我的 index.html 中加载 jQuery 后调用)

$(document).ready(function(){
    $.get("./scripts/elastic.php", function( data ) {
      console.log(data);
    });
});
4

1 回答 1

1

我认为正在发生的是,您的最终handlers指令是告诉部署将应用程序中的所有文件视为可上传和静态的。我相信这会导致您对早期脚本的调用处理不当(可能是 App Engine 错误...)。

如果您将最终处理程序更改为 PHP 脚本或类似以下内容,那么您应该很好:

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

您还希望在响应中包含您的 PHP 脚本echoprint结果,而不是return,它实际上不会向浏览器返回任何内容以供显示。

于 2017-10-25T05:34:34.680 回答