簡體   English   中英

Apache2.4 mod_wsgi錯誤:禁止您沒有訪問此服務器上的權限

[英]Apache2.4 mod_wsgi error: Forbidden You don't have permission to access / on this server

我正在使用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網絡應用托管同一台服務器,但出現錯誤

 <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

您作為Directory指令的參數給出的Directory/opt/cashpro/cashfiles ,它應該是/opt/cashpro/python_app/cashsite/trunk/cash/ 即,WSGI腳本文件所在的位置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM