【问题标题】:GCP/Django - Server cannot serve a simple htmlresponseGCP/Django - 服务器无法提供简单的 htmlresponse
【发布时间】:2022-06-13 22:13:30
【问题描述】:

因此,虽然我已成功让 django 应用程序在本地提供服务并使用 GCP SQL 作为后端,但在部署主应用程序后,我很难使用 Google App Engine(标准)获得任何成功的请求响应。即使是简单的 htmlresponse 消息也不起作用。这里有什么建议吗?

需要注意的一些奇怪的事情:有 500 个关于“favicon.ico”的请求,即使我不使用 ico 文件而是使用 png。完全删除 favicon 会产生类似的结果,但现在显示“GET / HTTP/1.1 500”(不知道这是什么意思)

views.py(缩写)

def index(request):
    return HttpResponse("Congratulations!")

app.yaml

runtime: python39

env_variables:
  BUCKET_NAME: "mystoragebucket"
  APPENGINE_URL: https://my-project-123456789101.uk.r.appspot.com/

handlers:
- url: /static
  static_dir: static/

- url: /.*
  script: auto

settings.py(缩写)

DEBUG=False
APPENGINE_URL = os.getenv('APPENGINE_URL')
ALLOWED_HOSTS = [APPENGINE_URL[8:]]
CSRF_TRUSTED_ORIGINS = [APPENGINE_URL]
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
    
STATIC_URL = "https://storage.googleapis.com/mypublicstaticbucket/static/"
SECRET_KEY = 'django-insecure-randomstringhere'

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'HOST': '/cloud_sql/my-project-123456789101:us-east4:MYSQLInstanceNameHere',
        'PORT' : 5432,
        'NAME': 'MyDBNameHere',
        'USER': 'myUsername',
        'PASSWORD': 'MyPassword',
    }
}

【问题讨论】:

  • 启用日志记录以获取有关错误的详细信息。
  • 您使用的是basic_scaling 还是automatic_scaling?另外,您设置了warmup_requests 还是min_idle_instances?当您启动基本扩展服务的实例时,App Engine 允许它接受流量,但 /.* 请求不会发送到实例,直到它收到第一个用户请求。检查:cloud.google.com/appengine/docs/standard/python/….

标签: django google-cloud-platform


猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-07-27
  • 2011-04-25
  • 2014-03-17
  • 1970-01-01
  • 2010-11-11
  • 2013-02-26
  • 1970-01-01
相关资源
最近更新 更多