我Django 2.0
使用pipenv
virtualenv创建了一个 python Web 应用程序
现在,我必须将它托管在 apache 服务器上。我已经安装libapache2-mod-wsgi-py3
并python-setuptools
在服务器中。
我的应用程序的结构就像
myapp_dir
|- myapp
|- settings
|- __init__.py
|- production.py
|- __init__.py
|- urls.py
|- wsgi.py
|- otherapp
|- templates
|- static_my_project
|- manage.py
|- Pipfile
|- Pipfile.lock
要放置的应用程序的路径
/home/user/app.application.com/
我已将所有文件移至目录并Pipfile
通过在目录中运行安装了所有依赖项
pipenv install
这已经创建了一个 virtualenv 并安装了所有必需的模块和给定的pipenv --venv
路径
# pipenv --venv
/home/user/.local/share/virtualenvs/app.application.com-IuTkL8w_
我的VirtualHost
配置看起来像
ServerName app.application.com
ServerAlias app.application.com
ErrorLog /home/user/error.log
CustomLog /home/user/custom.log combined
Alias /static /home/user/app.application.com/static_my_project
<Directory /home/user/app.application.com/static_my_project>
Require all granted
</Directory>
<Directory /home/user/app.application.com/pricearbitrase>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIScriptAlias / /home/user/app.application.com/myapp/wsgi.py
VirtualInclude 包含
<IfModule mod_wsgi>
WSGIPythonHome /home/user/.local/share/virtualenvs/app.application.com-IuTkL8w_
</IfModule>
但是在访问http://app.application.com
它时Internal server error
,生成的日志文件包含
[wsgi:error] [pid 60730] mod_wsgi (pid=60730): Target WSGI script '/home/amzitrage/app.amzitrage.com/pricearbitrase/wsgi.py' cannot be loaded as Python module.
[wsgi:error] [pid 60730] mod_wsgi (pid=60730): Exception occurred processing WSGI script '/home/amzitrage/app.amzitrage.com/pricearbitrase/wsgi.py'.
[wsgi:error] [pid 60730] Traceback (most recent call last):
[wsgi:error] [pid 60730] File "/home/amzitrage/app.amzitrage.com/pricearbitrase/wsgi.py", line 12, in <module>
[wsgi:error] [pid 60730] from django.core.wsgi import get_wsgi_application
[wsgi:error] [pid 60730] ImportError: No module named django.core.wsgi
编辑 2
app/wsgi.py
修改wsgi.py
文件激活virtual environment
activate_this = '/home/user/.local/share/virtualenvs/app.application.com-IuTkL8w_/bin/activate_this.py'
exec(compile(open(activate_this,"rb").read(),activate_this, 'exec'), dict(__file__=activate_this))
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "application.settings")
application = get_wsgi_application()
另外,ls -l /path_to_pipenv_venv/bin
给