在我的Django项目的生产中没有加载静态文件。我使用mod-wsgi来提供静态文件。
静态文件在开发中服务很好(当DEBUG = True时),但是现在我在尝试调用静态文件时遇到404错误。
我的文件结构是:https://imgur.com/a/FuFZSSh
/etc/Apache2/sites-available/my site.conf
<VirtualHost *:80>
ServerName <ip address>
ErrorLog ${APACHE_LOG_DIR}/mysite-error.log
CustomLog ${APACHE_LOG_DIR}/mysite-access.log combined
WSGIDaemonProcess mysite processes=2 threads=25 python-path=/var/www/mysite
WSGIProcessGroup mysite
WSGIScriptAlias / /var/www/mysite/mysite/wsgi.py
Alias /robots.txt /var/www/mysite/static/robots.txt
Alias /favicon.ico /var/www/mysite/static/favicon.ico
Alias /static/ /var/www/mysite/static/
Alias /media/ /var/www/mysite/media/
<Directory /var/www/mysite/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory /var/www/mysite/static>
Require all granted
</Directory>
<Directory /var/www/mysite/media>
Require all granted
</Directory>
</VirtualHost>
settings.朋友
STATIC_ROOT = '/var/www/mysite/static_root/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
STATIC_URL = '/static/'
MEDIA_ROOT = '/var/www/mysite/media/'
MEDIA_URL = '/media/'
任何帮助将不胜感激 :)
ol'可靠:DigitalOcean
how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-16-04
在运行collectstatic
之后,Apache应该查看您的STATIC_ROOT目录。
<Directory /var/www/mysite/static_root>
Require all granted
</Directory>