【问题标题】:HTML Website on Google App EngineGoogle App Engine 上的 HTML 网站
【发布时间】:2026-02-03 12:15:02
【问题描述】:

我在 Google App Engine 上有一个静态 html 网站。唯一的流量是我自己访问该网站进行测试。我注意到它很快消耗了 Frontend Instance Hours。是否可以让它不创建任何实例,以便不消耗前端实例时间?谢谢!

我的文件结构是这样的: 我的根文件夹中有我的 index.html 文件、其他几个 html 文件和一个 pdf 文档。图像文件位于根目录内的 IMAGE 文件夹中。 css 位于根目录内的 FILES 文件夹中。 FILES 文件夹还有一个主题文件夹,其中包含图像和 css 文件。

我的完整 app.yaml 如下所示:

应用程序:myappname
版本:1
运行时:python
api_version: 1

处理程序:
-url: /(.*.(gif|png|jpg|ico|js|css|pdf))
静态文件:\1
上传:(.*.(gif|png|jpg|ico|js|css|pdf))

-网址:.*
脚本:main.py

main.py 文件如下所示:

导入操作系统
从 google.appengine.ext 导入 webapp
从 google.appengine.ext.webapp 导入实用程序
从 google.appengine.ext.webapp 导入模板

类 MainHandler(webapp.RequestHandler):
def get (self, q):
如果 q 为无:
q = 'index.html'

path = os.path.join (os.path.dirname (__file__), q)
self.response.headers ['Content-Type'] = 'text/html'
self.response.out.write (template.render (path, {}))

def main():
application = webapp.WSGIApplication ([('/(.*html)?', MainHandler)], debug=True)
util.run_wsgi_app(应用程序)

如果 __ name __ == '__ main __':
主()

没有 main.py 文件的 App.yaml 文件,成功了!!!!!! (-和url之间有一个空格)

应用程序:myappname
版本:1
运行时:python
api_version: 1

default_expiration: "7d"

处理程序:
-url: /(.*.(gif|png|jpg|ico|js|css|pdf|html))
静态文件:\1
上传:(.*.(gif|png|jpg|ico|js|css|pdf|html))

-网址:/
静态文件:index.html
上传:index.html

【问题讨论】:

    标签: google-app-engine


    【解决方案1】:

    您可以将文件作为静态文件上传,这样它只会消耗传出带宽而不消耗实例。
    https://developers.google.com/appengine/docs/python/config/appconfig#Static_File_Pattern_Handlers

    【讨论】:

    • 我是否也必须将 html 文件作为静态文件上传?如何将根文件夹中的文件作为静态文件上传?谢谢。
    • 是的,您必须将所有内容作为静态文件上传。我发布的链接中的文档确实解释了如何做到这一点。而这个developers.google.com/appengine/docs/python/config/… 是鼠标向上滚动我在上面发布的链接。
    • 无论我做什么,我最终还是会吃掉前端实例的时间。我对无法做到感到沮丧....我使用了代码:-url: /(.*\.(gif|png|jpg|ico|js|css|pdf|html)) static_files: static/ \1 上传:静态/(.*\.(gif|png|jpg|ico|js|css|pdf|html)) 和 - 网址:/images static_dir: static/images
    • 请更新您的问题或提出新问题以显示完整的 app.yaml 内容以及您的文件结构。
    • 您还需要将.html 文件匹配为静态文件。否则仍然会有MainHandler 提供文件。删除 app.yaml 中的 main.py 部分并使其在没有的情况下工作。您想要实现的是没有 python 处理程序,因此完全删除该文件。