mod_wsgi和apache2的服务器内部错误

时间:2022-10-05 18:58:50

I've been trying to deploy django-oscar's sandbox website on a server with mod_wsgi and apache2.

我一直在尝试使用mod_wsgi和apache2在服务器上部署django-oscar的沙箱网站。

The thing is, whenever I open the website's address, i get a 500 error with the following in my log :

问题是,每当我打开网站的地址时,我的日志中都会出现以下500错误:

[Fri May 22 16:53:48 2015] [error] [client 2.190.60.200] mod_wsgi (pid=28331): Exception occurred processing WSGI script '/tmp/mod_wsgi-localhost:8001:1000/htdocs/en-gb'.
[Fri May 22 16:53:48 2015] [error] [client 2.190.60.200] Traceback (most recent call last):
[Fri May 22 16:53:48 2015] [error] [client 2.190.60.200]   File "/usr/local/lib/python2.7/dist-packages/mod_wsgi/server/__init__.py", line 1299, in handle_request
[Fri May 22 16:53:48 2015] [error] [client 2.190.60.200]     return self.application(environ, start_response)
[Fri May 22 16:53:48 2015] [error] [client 2.190.60.200]   File "/var/www/setak/setakenv/setakmain/django-oscar/sites/sandbox/wsgi.py", line 24, in application
[Fri May 22 16:53:48 2015] [error] [client 2.190.60.200]     return _application(environ, start_response)
[Fri May 22 16:53:48 2015] [error] [client 2.190.60.200]   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 187, in __call__
[Fri May 22 16:53:48 2015] [error] [client 2.190.60.200]     response = self.get_response(request)
[Fri May 22 16:53:48 2015] [error] [client 2.190.60.200]   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 199, in get_response
[Fri May 22 16:53:48 2015] [error] [client 2.190.60.200]     response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Fri May 22 16:53:48 2015] [error] [client 2.190.60.200]   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 231, in handle_uncaught_exception
[Fri May 22 16:53:48 2015] [error] [client 2.190.60.200]     'request': request
[Fri May 22 16:53:48 2015] [error] [client 2.190.60.200]   File "/usr/lib/python2.7/logging/__init__.py", line 1166, in error
[Fri May 22 16:53:48 2015] [error] [client 2.190.60.200]     self._log(ERROR, msg, args, **kwargs)
[Fri May 22 16:53:48 2015] [error] [client 2.190.60.200]   File "/usr/lib/python2.7/logging/__init__.py", line 1258, in _log
[Fri May 22 16:53:48 2015] [error] [client 2.190.60.200]     self.handle(record)
[Fri May 22 16:53:48 2015] [error] [client 2.190.60.200]   File "/usr/lib/python2.7/logging/__init__.py", line 1268, in handle
[Fri May 22 16:53:48 2015] [error] [client 2.190.60.200]     self.callHandlers(record)
[Fri May 22 16:53:48 2015] [error] [client 2.190.60.200]   File "/usr/lib/python2.7/logging/__init__.py", line 1308, in callHandlers
[Fri May 22 16:53:48 2015] [error] [client 2.190.60.200]     hdlr.handle(record)
[Fri May 22 16:53:48 2015] [error] [client 2.190.60.200]   File "/usr/lib/python2.7/logging/__init__.py", line 748, in handle
[Fri May 22 16:53:48 2015] [error] [client 2.190.60.200]     self.emit(record)
[Fri May 22 16:53:48 2015] [error] [client 2.190.60.200]   File "/usr/lib/python2.7/logging/__init__.py", line 929, in emit
[Fri May 22 16:53:48 2015] [error] [client 2.190.60.200]     self.stream = self._open()
[Fri May 22 16:53:48 2015] [error] [client 2.190.60.200]   File "/usr/local/lib/python2.7/dist-packages/oscar/core/logging/handlers.py", line 26, in _open
[Fri May 22 16:53:48 2015] [error] [client 2.190.60.200]     return BaseFileHandler._open(self)
[Fri May 22 16:53:48 2015] [error] [client 2.190.60.200]   File "/usr/lib/python2.7/logging/__init__.py", line 916, in _open
[Fri May 22 16:53:48 2015] [error] [client 2.190.60.200]     stream = open(self.baseFilename, self.mode)
[Fri May 22 16:53:48 2015] [error] [client 2.190.60.200] IOError: [Errno 13] Permission denied: '/var/www/setak/setakenv/setakmain/django-oscar/sites/sandbox/logs/errors.log'

now I don't know what I've done wrong here, since I'm quite new at this. I know that there are two things wrong at once! First an exception happens in the script and second the log can't be written into the logfile because of a permission problem!

现在我不知道我在这里做错了什么,因为我对此很陌生。我知道一下子有两件事错了!首先在脚本中发生异常,然后由于权限问题而无法将日志写入日志文件!

now here is my wsgi.py script:

现在这是我的wsgi.py脚本:

import os
import sys
import site
import urllib

sys.stdout = sys.stderr

# Project root
root = '/var/www/setak/setakenv/setakmain/django-oscar/sites/sandbox'
sys.path.insert(0, root)

# Packages from virtualenv
activate_this = '/var/www/setak/setakenv/setakmain/django-oscar/oscar/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

# Set environmental variable for Django and fire WSGI handler
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
#import django.core.handlers.wsgi
from django.core.wsgi import get_wsgi_application
_application = get_wsgi_application()

def application(environ, start_response):
    environ['PATH_INFO'] = urllib.unquote(environ['REQUEST_URI'].split('?')[0])
    return _application(environ, start_response)

and this is my apache2 config:

这是我的apache2配置:

<VirtualHost *:8080>
        WSGIDaemonProcess setak python-path=/var/www/setak/setakenv/setakmain/django-oscar/sites/sandbox:/var/www/setak/setakenv/lib/python2.7/site-packages
        WSGIProcessGroup setak
        WSGIScriptAlias / /var/www/setak/setakenv/setakmain/django-oscar/sites/sandbox/wsgi.py
        ServerAdmin admin@setakshop.ir
        ServerName shop.setakshop.ir

        Alias /robots.txt /var/www/setak/setakenv/setakmain/django-oscar/sites/sandbox/static/robots.txt

        Alias /media/ /var/www/setak/setakenv/setakmain/django-oscar/sites/sandbox/public/media/
        Alias /static/ /var/www/setak/setakenv/setakmain/django-oscar/sites/sandbox/public/static/

        <Directory /var/www/setak/setakenv/setakmain/django-oscar/sites/sandbox/public/static>
                Order allow,deny
                allow from all
        </Directory>

        <Directory /var/www/setak/setakenv/setakmain/django-oscar/sites/sandbox/public/media>
                Order allow,deny
                allow from all
        </Directory>

        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

I also run the project with the command :

我还使用命令运行项目:

mod_wsgi-express start-server wsgi.py --port=8001     --user www-data --group www-data

and also the simpler command :

还有更简单的命令:

mod_wsgi-express start-server wsgi.py --port=8001

but the same thing happens.

但同样的事情发生了。

I don't know what I'm doing wrong and any help would be appreciated. thanks in advance.

我不知道我做错了什么,任何帮助都会受到赞赏。提前致谢。

1 个解决方案

#1


1  

Try by changing permission to 777.But it is not recommended.(Try changing owner is good approach.)

尝试将权限更改为777.但不建议这样做。(尝试更改所有者是一种很好的方法。)

sudo chmod 777 /var/www/setak/setakenv/setakmain/django-oscar/sites/sandbox/logs/errors.log

#1


1  

Try by changing permission to 777.But it is not recommended.(Try changing owner is good approach.)

尝试将权限更改为777.但不建议这样做。(尝试更改所有者是一种很好的方法。)

sudo chmod 777 /var/www/setak/setakenv/setakmain/django-oscar/sites/sandbox/logs/errors.log