修改 sudo vi /etc/hosts
添加127.0.0.1 localhost
找到apache主配置文件,我这边是在/etc/apache2/
修改 httpd.conf
找到修改为 ServerName localhost:80
添加 LoadModule wsgi_module libexec/apache2/mod_wsgi.so
注意mod_wsgi.so
是从网上下载的,并且注意相对路径,我这边是libexec/apache2/
对应ServerRoot /usr/
修改/etc/apache2/extra/httpd-vhosts.conf
虚拟主机配置文件
WSGIPythonPath /Users/username/django/mysite
# 这是你project的位置
<VirtualHost *:80>
ServerName localhost
DocumentRoot "/Library/WebServer/Documents"
<Directory /Library/WebServer/Documents>
Require all granted
</Directory>
#注意 要运行`sudo chmod -R 755 /Library/WebServer/Documents`
#注意 Apache 2.4 以下要把"Require all granted" 改为
Order allow,deny
Allow from all
#注意添加目录进入权限的操作对所有<Directory>都要执行,不然就可能发生Apache无法访问指定目录的错误
WSGIScriptAlias / /Users/username/django/mysite/mysite/wsgi.py
<Directory /Users/username/django/mysite/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /static/ /Volumes/Blue/mystatic/
# 映射localhost/static/ 到你存放static文件的位置,不要漏掉斜杠'/'
<Directory /static/ /Volumes/Blue/mystatic>
Require all granted
</Directory>
</VirtualHost>
修改settings.py
确保
STATIC_URL = '/static/'
STATIC_ROOT = '/Volumes/Blue/mystatic'
# 你存放static文件的位置
我这里用的是httpd命令重启apache
sudo httpd start
#可以看到命令提示
sudo httpd -t 可以检查配置文件的syntax error
sudo httpd -t -D DUMP_VHOSTS 显示解析的vhost 设置
sudo httpd -t -D DUMP_RUN_CFG 显示设置
sudo httpd -k start|restart|stop
sudo httpd -k restart
部署完后
登陆 http://localhost
可以查看是否成功。
另外部署wsgi daemon mode
https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/modwsgi/#using-mod-wsgi-daemon-mode