django static + apache mod_wsgi部署

0.基本配置

/path/to/mysite.com/是项目路径。替换成实际的就好了。

WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py
WSGIPythonPath /path/to/mysite.com

<Directory /path/to/mysite.com/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

另外如果你用apache2.2,那么需要改Require语法。

<Files wsgi.py>
Allow from all
Order deny,allow
</Files>

1.静态文件

在setting.py文件中定义STATIC_ROOT

STATIC_ROOT = "/var/www/example.com/static/"

生成静态文件

python manage.py collectstatic

然后用apache的Alias就可以了。

Alias /media/ /path/to/mysite.com/media/
Alias /static/ /path/to/mysite.com/static/

猜你喜欢

转载自blog.csdn.net/aca_jingru/article/details/51426290