【问题标题】:Google Cloud is not serving my static filesGoogle Cloud 不提供我的静态文件
【发布时间】:2019-06-13 06:38:07
【问题描述】:

我已经部署了我的 laravel 应用程序,它在我的 PC 上成功运行。但是在部署到 gcloud 之后,我尝试访问它,但它无法加载在“public/”目录中创建的所有静态资产。我收到所有静态文件的 404 错误。使用 Web Engine 源代码视图我检查了文件,所有文件都在 gcloud 中可用。请让我知道如何从 gcloud 提供我的静态文件。

请找到我的 app.yaml 文件。

runtime: php72

env_variables:
  ## Put production environment variables here.
  APP_KEY: My_Key
  APP_STORAGE: /tmp
  VIEW_COMPILED_PATH: /tmp
  SESSION_DRIVER: cookie

  ## Set these environment variables according to your CloudSQL configuration.
  DB_DATABASE: mydb
  DB_USERNAME: myuser
  DB_PASSWORD: my_password
  DB_SOCKET: "/cloudsql/myproject:us-central1:myconn"


runtime_config:
 document_root: public

【问题讨论】:

  • 考虑使用云存储托管静态网站cloud.google.com/storage/docs/hosting-static-website
  • 所以没有其他方法可以提供公共文件?
  • 当您说您部署到 gcloud 时,您的意思是您使用的是 App Engine?如果是这样,它是标准的还是灵活的,你能分享你的 app.yaml 的布局吗?
  • @CorinneWhite 在问题中添加了 app.yaml 内容

标签: laravel google-app-engine google-cloud-platform gcloud


【解决方案1】:

有两种不同的 AppEngine 类型具有不同的 app.yam 配置:

  1. 灵活: 使用 document_root 配置和指向您的静态内容的 app.php。
    你可以找到complete example of the app.yaml and app.php files on the github
    env: flex 可以将应用程序部署为柔性环境。
    因此,如果您想使用灵活的环境,您的 app.yaml 可能如下所示:
runtime: php72
env: flex
env_variables:
               ...
               ...
runtime_config:
    document_root: public
  1. 标准: 使用http_handlers handlers
    将目录提供为作为静态资源的示例:
runtime: php72
handlers: 
- url: /public
  static_dir: public

另一个例子,从静态目录提供内容

runtime: php72
handlers: 
- url: /
  static_dir: public

More php app.yaml directory configuration handlers examples

配置目录总是相对于你的 app.yaml 文件位置

【讨论】:

    猜你喜欢
    • 2017-08-15
    • 1970-01-01
    • 1970-01-01
    • 2017-04-12
    • 2012-06-15
    • 2018-10-23
    • 2021-07-08
    • 2013-06-02
    • 2012-12-06
    相关资源
    最近更新 更多