经过 2 天的尝试多个教程并阅读 StackOverflow 后,我正在寻求帮助!
那个设定:
开发版本在AWS Lightsail服务器上顺利运行。在生产部署期间,我不断遇到静态文件问题。该应用程序在指定的子域上运行,但缺少所有 JS/CSS/images/...
我已按照官方文档进行操作,但没有效果。
1/https://docs.bitnami.com/aws/infrastruct/django/get-started/deploy-django-project/ https://docs.bitnami.com/aws/infrastructure/django/get-started/deploy-django-project/
2/ https://docs.bitnami.com/aws/infrastruct/django/get-started/deploy-django-project/ https://docs.bitnami.com/aws/infrastructure/django/get-started/deploy-django-project/
我的文件夹树及相关文件:
Project
- conf
- httpd-app.conf
- httpd-prefix.conf
- Django2Tutorial
- settings.py
- wsgi.py
- Solar
- static
- static (after running collectstatic function in terminal,-it includes the admin, Solar statics)
我的设置:
STATIC_ROOT = os.path.join(BASE_DIR,'static')
STATIC_URL = '/static/'
DEBUG = False
ALLOWED_HOSTS = ['54.169.172.***']
wsgi.py 文件
import os
import sys
sys.path.append('/opt/bitnami/apps/django/django_projects/Project')
os.environ.setdefault("PYTHON_EGG_CACHE", "/opt/bitnami/apps/django/django_projects/Project/egg_cache")
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'DjangoTutorial2.settings')
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
我的配置文件:
1.httpd-app.conf文件
<IfDefine !IS_DJANGOSTACK_LOADED>
Define IS_DJANGOSTACK_LOADED
WSGIDaemonProcess wsgi-djangostack processes=2 threads=15 display-name=%{GROUP}
</IfDefine>
<Directory "/opt/bitnami/apps/django/django_projects/Project/DjangoTutorial2">
Options +MultiViews
AllowOverride All
<IfVersion >= 2.3>
Require all granted
</IfVersion>
WSGIProcessGroup wsgi-djangostack
WSGIApplicationGroup %{GLOBAL}
</Directory>
Alias /static "/opt/bitnami/apps/django/django_projects/Project/static"
<Directory "/opt/bitnami/apps/django/django_projects/Project/static">
Require all granted
</Directory>
WSGIScriptAlias / '/opt/bitnami/apps/django/django_projects/Project/DjangoTutorial2/wsgi.py'
2.httpd-prefix.conf文件
# Include file
RewriteEngine On
RewriteCond "%{HTTP_HOST}" ^ec2-([0-9]{1,3})-([0-9]{1,3})-([0-9]{1,3})-([0-9]{1,3})\..*\.amazonaws.com(:[0-9]*)?$
RewriteRule "^/?(.*)" "%{REQUEST_SCHEME}://%1.%2.%3.%4%5/$1" [L,R=302,NE]
Include "/opt/bitnami/apps/django/django_projects/Project/conf/httpd-app.conf"
所做的其他调整:(/opt/bitnami/apache2/conf/bitnami)1/bitnami-apps-prefix.conf 文件
Include "/opt/bitnami/apps/django/django_projects/Project/conf/httpd-prefix.conf"
2/bitnami.conf文件
VirtualHost _default_:80>
WSGIScriptAlias / /opt/bitnami/apps/django/django_projects/Project/DjangoTutorial2/wsgi.py
<Directory /opt/bitnami/apps/django/django_projects/Project>
AllowOverride all
Require all granted
Options FollowSymlinks
</Directory>
DocumentRoot /opt/bitnami/apps/django/django_projects/Project
</VirtualHost>
- bitnami-apps-vhosts.conf 文件为空?这可以吗?
还检查了:
- 多次重启 Apache
- 玩弄 static_url 与 static_root
谁能建议如何进行?这两天真是太郁闷了哈哈。
请注意,也许这可以帮助:
使用 findstatic 函数进行双重检查,它将我重定向到 Solar/static 文件夹。我想既然我运行了collect static,我应该指向apacheconf中的项目级静态文件夹而不是Solar级静态文件夹。