我认为这是一个常见的问题,但我尝试过的解决方案中没有一个是有效的。
<VirtualHost *:80>
ServerName xxxx
ServerAdmin xxxx
DocumentRoot /home/matousc/apps/iacah
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /static /home/matousc/apps/iacah/www/static
<Directory /home/matousc/apps/iacah/www/static>
Require all granted
Allow from all
</Directory>
<Directory /home/matousc/apps/iacah/app/mainapp>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess iacah python-path=/home/matousc/apps/iacah/app python-home=/home/matousc/apps/appenv
WSGIProcessGroup iacah
WSGIScriptAlias / /home/matousc/apps/iacah/app/mainapp/wsgi.py
</VirtualHost>
我可以通过互联网访问该页面,所以
我确信我正在编辑正确的apacheconf文件
. 但是,不会加载静态文件。
静态文件不会随一起下载
403错误
. 我注意到,如果我更改行:
Alias /static/ /home/matousc/apps/iacah/www/static
static
:
Alias /static /home/matousc/apps/iacah/www/static
那我就去
. 在教程中,我看到了这两种选择,所以我有点困惑为什么它可以发挥作用。
业主
/www/
文件夹是
www-data
(我正在使用ubuntu 18):
drwxrwx--x 3 www-data www-data 4096 Sep 21 10:14 .
drwxr-xr-x 8 matousc matousc 4096 Sep 21 10:14 ..
drwxrwxrwx 12 www-data www-data 4096 Sep 21 10:14 static
我使用这台机器作为多主机,我还有一个静态网站,可以正常工作(文件被正确地提供)
<VirtualHost *:80>
ServerName xxxxx
ServerAdmin xxxx
DocumentRoot /home/matousc/apps/placeholder
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /home/matousc/apps/placeholder>
Require all granted
Options +Indexes
AllowOverride None
Order allow,deny
Allow from all
</Directory>
在Django中,我使用(我希望推荐)设置:
STATIC_URL = "/static/"
if production_machine:
level_up = os.path.dirname(BASE_DIR)
STATIC_ROOT = os.path.join(level_up, "www", "static")
STATICFILES_DIRS = (
STATIC_ROOT,
)
else:
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
(修订)
production_machine
应该是真的)。