我试图通过一个小型的Django站点从一个服务器移植到另一个服务器。在新服务器上,我安装了以下组件:
Ubuntu 16.04.3 LTS
Python 3.5.2
apache 2.4.18
mod_wsgi 4.5.17 (built from source with Python 3.5)
django 1.11.4 (installed using pip3 **without** a virtualenv)
在apache2.conf文件的底部,我添加了以下几行
^{pr2}$其中/home/user/ProductionServer是我的django站点的根目录。在
站点内启用/000-默认.conf,我有以下内容:
<VirtualHost *:2799>
ServerName myserver.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
WSGIScriptAlias / /home/user/ProductionServer/my_app/wsgi.py
Alias /static /home/user/ProductionServer/static
<Directory /home/user/ProductionServer/my_app>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory /home/user/ProductionServer/static>
Require all granted
</Directory>
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
我可以使用管理.pyrunserver命令。但是,当我通过apache运行它时,在apache2.error文件中收到以下错误消息:
[Tue Aug 08 10:53:39.291771 2017] [mpm_event:notice] [pid 1892:tid 139862763386752] AH00489: Apache/2.4.18 (Ubuntu) mod_wsgi/4.5.17 Python/3.5 configured -- resuming normal operations
[Tue Aug 08 10:53:39.291903 2017] [core:notice] [pid 1892:tid 139862763386752] AH00094: Command line: '/usr/sbin/apache2'
[Tue Aug 08 10:53:49.966143 2017] [wsgi:error] [pid 1893:tid 139862665881344] [client 85.97.123.183:56389] mod_wsgi (pid=1893): Target WSGI script '/home/user/ProductionServer/my_app/wsgi.py' cannot be loaded as Python module.
[Tue Aug 08 10:53:49.966273 2017] [wsgi:error] [pid 1893:tid 139862665881344] [client 85.97.123.183:56389] mod_wsgi (pid=1893): Exception occurred processing WSGI script '/home/user/ProductionServer/my_app/wsgi.py'.
[Tue Aug 08 10:53:49.966521 2017] [wsgi:error] [pid 1893:tid 139862665881344] [client 85.97.123.183:56389] Traceback (most recent call last):
[Tue Aug 08 10:53:49.966584 2017] [wsgi:error] [pid 1893:tid 139862665881344] [client 85.97.123.183:56389] File "/home/user/ProductionServer/my_app/wsgi.py", line 12, in <module>
[Tue Aug 08 10:53:49.966595 2017] [wsgi:error] [pid 1893:tid 139862665881344] [client 85.97.123.183:56389] from django.core.wsgi import get_wsgi_application
[Tue Aug 08 10:53:49.966620 2017] [wsgi:error] [pid 1893:tid 139862665881344] [client 85.97.123.183:56389] ImportError: No module named 'django'
我的文件夹结构如下:
ProductionServer
├── another_app
│ ├── ....
├── manage.py
├── my_app
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── static
└── ...
有什么想法吗?在
如果使用守护程序模式,可以在
WSGIScriptAlias
之前添加两行您可以检查django manual
示例
问题是,尽管我最初是这么想的,但pip只为我的本地用户安装了django。为了在全局范围内安装django,我必须使用-H选项运行pip:
相关问题 更多 >
编程相关推荐