我正在使用Ubuntu 14.04。 我在/ opt / cashpro / python_app / cashsite / trunk / cash下创建了一个django项目 并在同一目录中创建一个wsgi文件cash.wsgi
以下是cash.wsgi的内容
import os
import sys
path = '/opt/cashpro/python_app/cashsite/trunk/'
sys.path.insert(0, path)
from cash import settings
import django.core.management
sys.path.insert(1, '/opt/cashpro/python_app/cashsite/trunk/cash/')
django.core.management.setup_environ(settings)
utility = django.core.management.ManagementUtility()
command = utility.fetch_command('runserver')
command.validate()
import django.conf
import django.utils
django.utils.translation.activate(django.conf.settings.LANGUAGE_CODE)
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
以下是我添加到httpd.conf中的内容:
<VirtualHost *:443>
ServerName www.abcd.org
DocumentRoot /var/www/test
SSLEngine on
SSLCipherSuite HIGH:+MEDIUM:!SSLv2:!EXP:!ADH:!aNULL:!eNULL:!NULL
SSLCertificateFile "/opt/certs/www.abcd.org.crt"
SSLCertificateKeyFile "/opt/ssl/www.abcd.key"
SSLCertificateChainFile "/opt/certs/DigiCertCA.crt"
#SSLCertificateChainFile "/opt/ssl/IntermediatesCA3.crt"
BrowserMatch ".*MSIE.*" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
Alias /media-cash/ /opt/cashpro/cashfiles
<Directory /opt/cashpro/cashfiles>
Options MultiViews
AllowOverride None
Require all granted
</Directory>
WSGIPassAuthorization On
WSGIScriptAlias /site
/opt/cashpro/python_app/cashsite/trunk/cash/cash.wsgi
ErrorLog /var/log/apache2/serror.log
CustomLog /var/log/apache2/saccess.log common
</VirtualHost>
问题是,当我访问https://www.abcd.org/site时,它说
禁止
您无权访问此服务器上的/。
Apache错误日志
[Thu Jul 20 22:24:56.263573 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] mod_wsgi (pid=4448): Target WSGI script
'/opt/cashpro/python_app/cashsite/trunk/cash/cash.wsgi' cannot be loaded as
Python module., referer: https://www.abcd.org
[Thu Jul 20 22:24:56.263816 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] mod_wsgi (pid=4448): Exception occurred
processing WSGI script
'/opt/cashpro/python_app/cashsite/trunk/cash/cash.wsgi'., referer:
https://www.abcd.org
[Thu Jul 20 22:24:56.263978 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] Traceback (most recent call last):, referer:
https://www.abcd.org
[Thu Jul 20 22:24:56.264085 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] File
"/opt/cashpro/python_app/cashsite/trunk/cash/cash.wsgi", line 11, in
<module>, referer: https://www.abcd.org
[Thu Jul 20 22:24:56.264223 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] command =
utility.fetch_command('runserver'), referer: https://www.abcd.org
[Thu Jul 20 22:24:56.264261 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] File "/usr/local/lib/python2.7/dist-
packages/django/core/management/__init__.py", line 261, in fetch_command,
referer: https://www.abcd.org
[Thu Jul 20 22:24:56.264325 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] klass = load_command_class(app_name,
subcommand), referer: https://www.abcd.org
[Thu Jul 20 22:24:56.264360 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] File "/usr/local/lib/python2.7/dist-
packages/django/core/management/__init__.py", line 69, in
load_command_class, referer: https://www.abcd.org
[Thu Jul 20 22:24:56.264410 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] module =
import_module('%s.management.commands.%s' % (app_name, name)), referer:
https://www.abcd.org
[Thu Jul 20 22:24:56.264452 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] File "/usr/local/lib/python2.7/dist-
packages/django/utils/importlib.py", line 35, in import_module, referer:
https://www.abcd.org
[Thu Jul 20 22:24:56.264495 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] __import__(name), referer:
https://www.abcd.org
[Thu Jul 20 22:24:56.264524 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] File "/usr/local/lib/python2.7/dist-
packages/django/core/management/commands/runserver.py", line 8, in <module>,
referer: https://www.abcd.org
[Thu Jul 20 22:24:56.264570 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] from django.core.servers.basehttp import
AdminMediaHandler, run, WSGIServerException, get_internal_wsgi_application,
referer: https://www.abcd.org
[Thu Jul 20 22:24:56.264599 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] File "/usr/local/lib/python2.7/dist-
packages/django/core/servers/basehttp.py", line 26, in <module>, referer:
https://www.abcd.org
[Thu Jul 20 22:24:56.264637 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] from django.views import static, referer:
https://www.abcd.org
[Thu Jul 20 22:24:56.264665 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] File "/usr/local/lib/python2.7/dist-
packages/django/views/static.py", line 95, in <module>, referer:
https://www.abcd.org
[Thu Jul 20 22:24:56.264700 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] template_translatable =
ugettext_noop(u"Index of %(directory)s"), referer: https://www.abcd.org
[Thu Jul 20 22:24:56.264727 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] File "/usr/local/lib/python2.7/dist-
packages/django/utils/translation/__init__.py", line 75, in gettext_noop,
referer: https://www.abcd.org
[Thu Jul 20 22:24:56.264780 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] return _trans.gettext_noop(message),
referer: https://www.abcd.org
[Thu Jul 20 22:24:56.264821 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] File "/usr/local/lib/python2.7/dist-
packages/django/utils/translation/__init__.py", line 48, in __getattr__,
referer: https://www.abcd.org
[Thu Jul 20 22:24:56.264852 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] if settings.USE_I18N:, referer:
https://www.abcd.org
[Thu Jul 20 22:24:56.264879 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] File "/usr/local/lib/python2.7/dist-
packages/django/utils/functional.py", line 184, in inner, referer:
https://www.abcd.org
[Thu Jul 20 22:24:56.264912 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] self._setup(), referer:
https://www.abcd.org
[Thu Jul 20 22:24:56.264938 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] File "/usr/local/lib/python2.7/dist-
packages/django/conf/__init__.py", line 42, in _setup, referer:
https://www.abcd.org
[Thu Jul 20 22:24:56.264987 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] self._wrapped = Settings(settings_module),
referer: https://www.abcd.org
[Thu Jul 20 22:24:56.265015 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] File "/usr/local/lib/python2.7/dist-
packages/django/conf/__init__.py", line 135, in __init__, referer:
https://www.abcd.org
[Thu Jul 20 22:24:56.265044 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] logging_config_func(self.LOGGING),
referer: https://www.abcd.org
[Thu Jul 20 22:24:56.265071 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] File "/usr/lib/python2.7/logging/config.py",
line 794, in dictConfig, referer: https://www.abcd.org
[Thu Jul 20 22:24:56.265116 2017] [:error] [pid 4448:tid 140570219427584] [
client xxx.xxx.xxx.xxx:3340] dictConfigClass(config).configure(),
referer: https://www.abcd.org
[Thu Jul 20 22:24:56.265151 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] File "/usr/lib/python2.7/logging/config.py",
line 576, in configure, referer: https://www.abcd.org
[Thu Jul 20 22:24:56.265201 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] '%r: %s' % (name, e)), referer:
https://www.abcd.org
[Thu Jul 20 22:24:56.265284 2017] [:error] [pid 4448:tid 140570219427584]
[client xxx.xxx.xxx.xxx:3340] ValueError: Unable to configure handler
'default': [Errno 13] Permission denied: '/opt/cash_site.log', referer:
https://www.abcd.org
另一个python web应用程序托管同一台服务器。但是收到错误
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName www.xyz.com
ServerAlias xyz.com
DocumentRoot /opt/nadasnapp/html
<Directory /opt/nadasnapp/html/>
Require all granted
AllowOverride All
</Directory>
LogLevel warn
##FOR NADA
Alias /media/ /opt/nadasnapp/python_app/NaDaWebPro/media/
<Directory /opt/nadasnapp/python_app/NaDaWebPro/media/>
Require all granted
AllowOverride All
</Directory>
Alias /static/ /opt/nadasnapp/python_app/NaDaWebPro/static_root/
<Directory /opt/nadasnapp/python_app/NaDaWebPro/static_root/>
Require all granted
AllowOverride All
</Directory>
#FOR NADA
WSGIPassAuthorization On
WSGIScriptAlias / /opt/nadasnapp/python_app/NaDaWebPro/nada/wsgi.py
<Directory /opt/nadasnapp/python_app/NaDaWebPro/nada>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
错误是
[Sun Jul 23 04:23:14.151745 2017] [:error] [pid 4594:tid
139820915422976]
[client xxx.xxx.xxx.xxx:2244] mod_wsgi (pid=4594): Exception occurred
processing WSGI script
'/opt/nadasnapp/python_app/NaDaWebPro/nada/wsgi.py'.
[Sun Jul 23 04:23:14.151993 2017] [:error] [pid 4594:tid 139820915422976]
[client xxx.xxx.xxx.xxx:2244] Traceback (most recent call last):
[Sun Jul 23 04:23:14.152065 2017] [:error] [pid 4594:tid 139820915422976]
[client xxx.xxx.xxx.xxx:2244] File "/usr/local/lib/python2.7/dist-
packages/django/core/handlers/wsgi.py", line 219, in __call__
[Sun Jul 23 04:23:14.152135 2017] [:error] [pid 4594:tid 139820915422976]
[client xxx.xxx.xxx.xxx:2244] self.load_middleware()
[Sun Jul 23 04:23:14.152166 2017] [:error] [pid 4594:tid 139820915422976]
[client xxx.xxx.xxx.xxx:2244] File "/usr/local/lib/python2.7/dist-
packages/django/core/handlers/base.py", line 39, in load_middleware
[Sun Jul 23 04:23:14.152203 2017] [:error] [pid 4594:tid 1
39820915422976]
[client xxx.xxx.xxx.xxx:2244] for middleware_path in
settings.MIDDLEWARE_CLASSES:
[Sun Jul 23 04:23:14.152234 2017] [:error] [pid 4594:tid 139820915422976]
[client xxx.xxx.xxx.xxx:2244] File "/usr/local/lib/python2.7/dist-
packages/django/utils/functional.py", line 184, in inner
[Sun Jul 23 04:23:14.152319 2017] [:error] [pid 4594:tid 139820915422976]
[client xxx.xxx.xxx.xxx:2244] self._setup()
[Sun Jul 23 04:23:14.152357 2017] [:error] [pid 4594:tid 139820915422976]
[client xxx.xxx.xxx.xxx:2244] File "/usr/local/lib/python2.7/dist-
packages/django/conf/__init__.py", line 42, in _setup
[Sun Jul 23 04:23:14.152402 2017] [:error] [pid 4594:tid 139820915422976]
[client xxx.xxx.xxx.xxx:2244] self._wrapped =
Settings(settings_module)
[Sun Jul 23 04:23:14.152445 2017] [:error] [pid 4594:tid 139820915422976]
[client xxx.xxx.xxx.xxx:2244] File "/usr/local/lib/python2.7/dist-
packages/django/conf/__init__.py", line 95, in __init__
[Sun Jul 23 04:23:14.152484 2017] [:error] [pid 4594:tid 139820915422976]
[client xxx.xxx.xxx.xxx:2244] raise ImportError("Could not import
settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
[Sun Jul 23 04:23:14.152540 2017] [:error] [pid 4594:tid 139820915422976]
[client xxx.xxx.xxx.xxx:2244] ImportError: Could not import settings
'cash.settings' (Is it on sys.path?): No module named cash.settings
答案 0 :(得分:0)
您作为Directory
指令的参数提供的目录是/opt/cashpro/cashfiles
,它应该是/opt/cashpro/python_app/cashsite/trunk/cash/
。也就是说,WSGI脚本文件所在的位置。