我在 GCP VM 实例上使用 apache2 运行 django mod_wsgi,当我在 DEBUG=False 上运行它时,静态文件工作正常,但是当我检查媒体文件时,它们得到 404,而文件显然存在于服务器上。我的 conf 基于以下 django 文档https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/modwsgi/#serving-files
#settings.py
MEDIA_ROOT = os.path.join(PROJECT_ROOT, "media")
MEDIA_URL = os.environ.get("MEDIA_URL", "/media/")
STATIC_ROOT = os.path.join(PROJECT_ROOT, "static")
STATIC_URL = os.environ.get("STATIC_URL", "/static/")
#apache2
Alias /media/ /home/ubuntu/myshop/media/
Alias /static/ /home/ubuntu/myshop/static/
<Directory /home/ubuntu/myshop/media>
Require all granted
</Directory>
<Directory /home/ubuntu/myshop/static>
Require all granted
</Directory>
尝试重新启动 apache2 甚至服务器,但也没有工作