我知道这个问题已在这里提出。我已经阅读了很多答案,但没有任何帮助。
我使用的是virtualenv(/ root / eb-virt);我的Django项目叫做mediar。所有公共文件都存储在/var/www/html/xxx.com/public_html /
中从错误日志:
[Sun Oct 16 18:40:11.737747 2016] [:error] [pid 27659] [client 128.75.240.205:60486] mod_wsgi (pid=27659): Target WSGI script '/var/www/html/xxx.com/django.wsgi' cannot be loaded as Python module.
[Sun Oct 16 18:40:11.737808 2016] [:error] [pid 27659] [client 128.75.240.205:60486] mod_wsgi (pid=27659): Exception occurred processing WSGI script '/var/www/html/xxx.com/django.wsgi'.
[Sun Oct 16 18:40:11.745983 2016] [:error] [pid 27659] [client 128.75.240.205:60486] Traceback (most recent call last):
[Sun Oct 16 18:40:11.746153 2016] [:error] [pid 27659] [client 128.75.240.205:60486] File "/var/www/html/xxx.com/django.wsgi", line 9, in <module>
[Sun Oct 16 18:40:11.746165 2016] [:error] [pid 27659] [client 128.75.240.205:60486] import django.core.handlers.wsgi
[Sun Oct 16 18:40:11.746191 2016] [:error] [pid 27659] [client 128.75.240.205:60486] ImportError: No module named 'django'
我的apache2.conf:
Mutex file:${APACHE_LOCK_DIR} default
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive Off
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
#<Directory /srv/>
# Options Indexes FollowSymLinks
# AllowOverride None
# Require all granted
#</Directory>
AccessFileName .htaccess
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf
<IfModule mpm_prefork_module>
StartServers 4
MinSpareServers 20
MaxSpareServers 40
MaxClients 200
MaxRequestsPerChild 4500
</IfModule>
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so
WSGIScriptAlias / /var/www/html/xxx.com/public_html/mediar/mediar/wsgi.py
WSGIPythonPath /var/www/html/xxx.com/public_html:/root/eb-virt/lib/python3.4/site-packages/
<Directory /var/www/html/xxx.com/public_html/mediar/mediar/>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
我的xxx.com.conf:
<VirtualHost *:80>
ServerAdmin xxx@xxx.com
ServerName xxx.com
ServerAlias www.xxx.com
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /var/www/html/xxx.com/public_html
# Log file locations
LogLevel warn
ErrorLog /var/www/html/xxx.com/log/error.log
CustomLog /var/www/html/xxx.com/log/access.log combined
WSGIScriptAlias / /var/www/html/xxx.com/django.wsgi
</VirtualHost>
最后,我的django.wsgi:
#!/usr/bin/python
import os, sys
PROJECT_ROOT = '/var/www/html/xxx.com/'
sys.path.append(PROJECT_ROOT)
os.environ['DJANGO_SETTINGS_MODULE'] = 'mediar.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
我已经尝试了
$ sudo apt-get remove libapache2-mod-python libapache2-mod-wsgi
$ sudo apt-get install libapache2-mod-wsgi-py3
,它没有任何帮助。
我该怎么办?
答案 0 :(得分:0)
我首先尝试在你的wsgi文件中使用正确的python shebang。不应该像以下那样吗?
#!/root/eb-virt/bin/python
然后第二件事是将virtualenv显式添加到wsgi文件中的sys.path
追加
sys.path.append('/root/eb-virt/lib/python3.4/site-packages')