我得到一个502坏网关错误与django应用程序在AppEngine



我在谷歌应用引擎上部署了一个django应用程序(灵活的环境)。该应用程序在本地运行良好,部署(使用gcloud app deploy)也很顺利。虽然主页加载良好,但当我使用pickle从同一应用程序目录中的目录(通过POST请求)加载一些二进制数据(约40Mo)时,我得到502坏网关nginx错误。我尝试了许多建议的解决方案(将PORT更改为8080,添加gunicorn超时或添加-preload,更改工作人员的n°…),但仍然存在问题。我认为问题来自于我加载了一个沉重的文件,因为我可以访问部署版本上的django admin .

我对gunicorn/nginx并不了解(这是我第一次部署应用程序)。如果你花了这么多时间在这上面,我将非常感谢你有一些想法!

日志文件没有显示任何错误:

2021-10-30 14:38:46 default[20211030t141946]  [2021-10-30 14:38:46 +0000] [1] [INFO] Starting gunicorn 19.9.0
2021-10-30 14:38:46 default[20211030t141946]  [2021-10-30 14:38:46 +0000] [1] [DEBUG] Arbiter booted
2021-10-30 14:38:46 default[20211030t141946]  [2021-10-30 14:38:46 +0000] [1] [INFO] Listening at: http://0.0.0.0:8080 (1)
2021-10-30 14:38:46 default[20211030t141946]  [2021-10-30 14:38:46 +0000] [1] [INFO] Using worker: sync
2021-10-30 14:38:46 default[20211030t141946]  [2021-10-30 14:38:46 +0000] [10] [INFO] Booting worker with pid: 10
2021-10-30 14:38:46 default[20211030t141946]  [2021-10-30 14:38:46 +0000] [1] [DEBUG] 1 workers
2021-10-30 14:39:04 default[20211030t133157]  "GET /nginx_metrics" 200
2021-10-30 14:39:31 default[20211030t141946]  [2021-10-30 14:39:31 +0000] [10] [DEBUG] GET /
2021-10-30 14:39:47 default[20211030t141946]  "GET /nginx_metrics" 200
2021-10-30 14:40:04 default[20211030t141946]  [2021-10-30 14:40:04 +0000] [10] [DEBUG] POST /
2021-10-30 14:40:04 default[20211030t141946]  POST REQUEST (I click here)
2021-10-30 14:40:20 default[20211030t133157]  [2021-10-30 14:40:20 +0000] [1] [INFO] Handling signal: term
2021-10-30 14:40:20 default[20211030t133157]  [2021-10-30 14:40:20 +0000] [14] [INFO] Worker exiting (pid: 14)
2021-10-30 14:40:21 default[20211030t133157]  [2021-10-30 14:40:21 +0000] [1] [INFO] Shutting down: Master
2021-10-30 14:40:47 default[20211030t141946]  "GET /nginx_metrics" 200

我的app.yaml文件:

runtime: python
env: flex
env_variables:
SECRET_KEY: 'DJANGO-SECRET-KEY' 
DEBUG: 'False' 

DB_HOST: '/cloudsql/django-naimai:europe-west1:naimai-sql'
DB_PORT: '5432' # PostgreSQL port
DB_NAME: 'postgres'
DB_USER: 'postgres' 
DB_PASSWORD: 'DB_PASSWORD'
entrypoint: gunicorn -b :$PORT --log-level=debug --timeout=120 django_naimai.wsgi
manual_scaling: 
instances: 1
beta_settings:
cloud_sql_instances: django-naimai-west1:naimai-sql
runtime_config:
python_version: 3
resources:
cpu: 2
memory_gb: 2.3
disk_size_gb: 20
volumes:
- name: ramdisk1
volume_type: tmpfs
size_gb: 2

My settings.py file:

DEBUG = os.environ['DEBUG']
ALLOWED_HOSTS = ["django-naimai.oa.r.appspot.com","127.0.0.1",]
DATABASES = {"default": {
'ENGINE': 'django.db.backends.postgresql',
'HOST': os.environ['DB_HOST'],
'PORT': os.environ['DB_PORT'],
'NAME': os.environ['DB_NAME'],
'USER': os.environ['DB_USER'],
'PASSWORD': os.environ['DB_PASSWORD']
}}
if os.getenv("USE_CLOUD_SQL_AUTH_PROXY", None):
DATABASES["default"]["HOST"] = "127.0.0.1"
DATABASES["default"]["PORT"] = 5432
GS_BUCKET_NAME="naimai_bucket"
STATIC_URL = "/static/"
DEFAULT_FILE_STORAGE = "storages.backends.gcloud.GoogleCloudStorage"
STATICFILES_STORAGE = "storages.backends.gcloud.GoogleCloudStorage"
GS_DEFAULT_ACL = "publicRead"

正如@gaefan建议的那样,我需要最大化内存!我在yaml文件中尝试了10个memory_gb,它工作了。

相关内容

  • 没有找到相关文章

最新更新