【问题标题】:App Engine YAML file not running scriptsApp Engine YAML 文件未运行脚本
【发布时间】:2017-10-24 18:42:13
【问题描述】:

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

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

但是一旦我将它列为 yaml 中的 php 文件并期望 jQuery GET 'hello, world!'它在 Firefox 网络监视器中返回 404,并且在控制台中没有响应。

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

app.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: (.*)

elastic.php

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

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

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

【问题讨论】:

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


    【解决方案1】:

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

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

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

    您还需要让您的 PHP 脚本 echoprint 产生响应,而不是 return,后者实际上不会向浏览器返回任何内容以供显示。

    【讨论】:

    • 你是 100% 正确的!出于某种原因,我认为它是级联的,以至于初始脚本处理程序在它们进一步进入漏斗之前就已经捕获了所有 php 文件。我调整了标题,以便您的回答可以帮助更多人。谢谢布雷特 :)
    • 它应该至少在 URL 匹配时以这种方式运行,但我认为在上传过程中文件被覆盖或重新分类为静态文件。我将打开一个关于该行为的错误,看看会发生什么。可能只是我们需要在文档中警告人们这可能会发生。
    猜你喜欢
    • 1970-01-01
    • 2012-11-19
    • 2015-05-10
    • 1970-01-01
    • 2016-03-25
    • 1970-01-01
    • 1970-01-01
    • 2011-04-20
    • 2017-04-25
    相关资源
    最近更新 更多