I';使用mod_wsgi使用Apache设置Django时遇到的问题
我已经试了很多次了,感觉自己被卡住了,没有取得任何进展,Apache给出了一个错误 ModuleNotFoundError:没有名为“wearpretty.settings”的模块 我正在使用 python 3.6, Django2.1, apache2, libapache2-mod-wsgi-py3 下面是本文档中使用的文件 wsgi.py virtualhost.confI';使用mod_wsgi使用Apache设置Django时遇到的问题,django,python-3.x,apache,mod-wsgi,Django,Python 3.x,Apache,Mod Wsgi,我已经试了很多次了,感觉自己被卡住了,没有取得任何进展,Apache给出了一个错误 ModuleNotFoundError:没有名为“wearpretty.settings”的模块 我正在使用 python 3.6, Django2.1, apache2, libapache2-mod-wsgi-py3 下面是本文档中使用的文件 wsgi.py virtualhost.conf 服务器管理员webmaster@localhost ServerName.com ServerAlias www.l
服务器管理员webmaster@localhost
ServerName.com
ServerAlias www.lhwearpretty.com
DocumentRoot/var/www/myprojects/wearpretty/wearpretty/wearpretty
要求所有授权
WSGIDaemonProcess lhwearpretty.com python home=/var/www/myprojects/wearpretty/venv python path=/var/www/myprojects/wearpretty
WSGIProcessGroup.com
WSGIScriptAlias//var/www/myprojects/wearpretty/wearpretty/wearpretty/wsgi.py
别名/static//var/www/myprojects/wearpretty/wearpretty/static/
要求所有授权
您的文档根目录应该向上一个文件夹(减去1/wearpretty
),而WSGIDaemonProcess中的python路径变量应该向下一个文件夹(加上1/wearpretty
):它们必须指向您的Django项目根目录
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName lhwearpretty.com
ServerAlias www.lhwearpretty.com
DocumentRoot /var/www/myprojects/wearpretty/wearpretty
<Directory /var/www/myprojects/wearpretty/wearpretty/wearpretty>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess lhwearpretty.com python-home=/var/www/myprojects/wearpretty/venv python-path=/var/www/myprojects/wearpretty/wearpretty
WSGIProcessGroup lhwearpretty.com
WSGIScriptAlias / /var/www/myprojects/wearpretty/wearpretty/wearpretty/wsgi.py
Alias /static /var/www/myprojects/wearpretty/wearpretty/static/
<Directory /var/www/myprojects/wearpretty/wearpretty/static>
Require all granted
</Directory>
</VirtualHost>
服务器管理员webmaster@localhost
ServerName.com
ServerAlias www.lhwearpretty.com
DocumentRoot/var/www/myprojects/wearpretty/wearpretty
要求所有授权
WSGIDaemonProcess lhwearpretty.com python home=/var/www/myprojects/wearpretty/venv python path=/var/www/myprojects/wearpretty/wearpretty
WSGIProcessGroup.com
WSGIScriptAlias//var/www/myprojects/wearpretty/wearpretty/wearpretty/wsgi.py
别名/static/var/www/myprojects/wearpretty/wearpretty/static/
要求所有授权
此外,我建议添加此目录节点:
<Directory /var/www/myprojects/wearpretty/wearpretty>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
选项索引跟随符号链接多视图
允许超越所有
命令允许,拒绝
通融
当我自己开始这项工作时,我发现我的目录命名存在一些问题。
任何第一次开始的人都应该知道你不能用你的站点目录名作为你的项目名。
所以我改了
旧结构
新结构
Virtualhost.conf
服务器管理员webmaster@localhost
ServerName.com
ServerAlias www.lhwearpretty.com
DocumentRoot/var/www/myprojects/wearpretty/mysite
WSGIDaemonProcess lhwearpretty.com python home=/var/www/myprojects/wearpretty/wearprettynv python path=/var/www/myprojects/wearpretty/mysite
WSGIProcessGroup.com
WSGIScriptAlias//var/www/myprojects/wearpretty/mysite/mysite/wsgi.py
要求所有授权
别名/static//var/www/myprojects/wearpretty/mysite/static/
要求所有授权
希望这也能帮助其他人。我也尝试过这一方法,几乎每一条我尝试过的路径都是form/var/www/myprojects/wearpretty/to/var/www/myprojects/wearpretty/wearpretty/wearpretty,但幸运的是,我的项目进展顺利。太好了。走吧!
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName lhwearpretty.com
ServerAlias www.lhwearpretty.com
DocumentRoot /var/www/myprojects/wearpretty/wearpretty
<Directory /var/www/myprojects/wearpretty/wearpretty/wearpretty>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess lhwearpretty.com python-home=/var/www/myprojects/wearpretty/venv python-path=/var/www/myprojects/wearpretty/wearpretty
WSGIProcessGroup lhwearpretty.com
WSGIScriptAlias / /var/www/myprojects/wearpretty/wearpretty/wearpretty/wsgi.py
Alias /static /var/www/myprojects/wearpretty/wearpretty/static/
<Directory /var/www/myprojects/wearpretty/wearpretty/static>
Require all granted
</Directory>
</VirtualHost>
<Directory /var/www/myprojects/wearpretty/wearpretty>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Site Dir = /var/www/myprojects/wearpretty
Project Dir = /var/www/myprojects/wearpretty/wearpretty
venv = /var/www/myprojects/wearpretty/venv
Site Dir = /var/www/myprojects/wearpretty
Project Dir = /var/www/myprojects/wearpretty/mysite
venv = /var/www/myprojects/wearpretty/venv
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName lhwearpretty.com
ServerAlias www.lhwearpretty.com
DocumentRoot /var/www/myprojects/wearpretty/mysite
WSGIDaemonProcess lhwearpretty.com python-home=/var/www/myprojects/wearpretty/wearprettyenv python-path=/var/www/myprojects/wearpretty/mysite
WSGIProcessGroup lhwearpretty.com
WSGIScriptAlias / /var/www/myprojects/wearpretty/mysite/mysite/wsgi.py
<Directory /var/www/myprojects/wearpretty/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /static/ /var/www/myprojects/wearpretty/mysite/static/
<Directory /var/www/myprojects/wearpretty/mysite/static>
Require all granted
</Directory>
</VirtualHost>