无法使用Apache和mod_wsgi使用简单的Django Web应用程序

时间:2012-11-13 01:40:09

标签: django apache webserver centos mod-wsgi

我一直坚持将我的Django项目转移到由DreamHost托管的生产CentOS服务器上。安装了Apache 2.2.23和Python 2.6.6。我已经安装并配置了Django 1.4和mod_wsgi 3.4。当我通过键入

重新启动Apache(希望Web应用程序能够完美运行)
sudo apachectl restart

我在/ usr / local / apache / logs /中查看Apache的error_log,看看:

[Mon Nov 12 18:05:24 2012] [info] Init: Seeding PRNG with 144 bytes of entropy
[Mon Nov 12 18:05:24 2012] [notice] SSL FIPS mode disabled
[Mon Nov 12 18:05:24 2012] [info] Loading certificate & private key of SSL-aware server
[Mon Nov 12 18:05:24 2012] [info] Init: Generating temporary RSA private keys (512/1024 bits)
[Mon Nov 12 18:05:24 2012] [info] Init: Generating temporary DH parameters (512/1024 bits)
[Mon Nov 12 18:05:24 2012] [info] Init: Initializing (virtual) servers for SSL
[Mon Nov 12 18:05:24 2012] [info] Configuring server for SSL protocol
[Mon Nov 12 18:05:24 2012] [warn] RSA server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
[Mon Nov 12 18:05:24 2012] [info] mod_ssl/2.2.23 compiled against Server: Apache/2.2.23, Library: OpenSSL/1.0.0-fips
[Mon Nov 12 18:05:24 2012] [notice] suEXEC mechanism enabled (wrapper: /usr/local/apache/bin/suexec)
[Mon Nov 12 18:05:24 2012] [info] Init: Seeding PRNG with 144 bytes of entropy
[Mon Nov 12 18:05:24 2012] [notice] SSL FIPS mode disabled
[Mon Nov 12 18:05:24 2012] [info] Loading certificate & private key of SSL-aware server
[Mon Nov 12 18:05:24 2012] [info] Init: Generating temporary RSA private keys (512/1024 bits)
[Mon Nov 12 18:05:24 2012] [info] Init: Generating temporary DH parameters (512/1024 bits)
[Mon Nov 12 18:05:24 2012] [info] Init: Initializing (virtual) servers for SSL
[Mon Nov 12 18:05:24 2012] [info] Configuring server for SSL protocol
[Mon Nov 12 18:05:24 2012] [warn] RSA server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
[Mon Nov 12 18:05:24 2012] [info] mod_ssl/2.2.23 compiled against Server: Apache/2.2.23, Library: OpenSSL/1.0.0-fips
[Mon Nov 12 18:05:24 2012] [info] mod_wsgi (pid=30259): Starting process 'myproject.mysite.net' with uid=99, gid=99 and threads=1.
[Mon Nov 12 18:05:24 2012] [info] mod_wsgi (pid=30259): Initializing Python.
[Mon Nov 12 18:05:24 2012] [info] mod_wsgi (pid=30260): Initializing Python.
[Mon Nov 12 18:05:24 2012] [info] mod_wsgi (pid=30261): Initializing Python.
[Mon Nov 12 18:05:24 2012] [info] mod_wsgi (pid=30262): Initializing Python.
[Mon Nov 12 18:05:24 2012] [info] mod_wsgi (pid=30263): Initializing Python.
[Mon Nov 12 18:05:24 2012] [info] mod_wsgi (pid=30264): Initializing Python.
[Mon Nov 12 18:05:24 2012] [notice] Apache/2.2.23 (Unix) mod_ssl/2.2.23 OpenSSL/1.0.0-fips mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 mod_wsgi/3.4 Python/2.6.6 configured -- resuming normal operations
[Mon Nov 12 18:05:24 2012] [info] Server built: Oct 21 2012 05:57:19
[Mon Nov 12 18:05:24 2012] [info] mod_wsgi (pid=30259): Attach interpreter ''.
[Mon Nov 12 18:05:24 2012] [info] mod_wsgi (pid=30260): Attach interpreter ''.
[Mon Nov 12 18:05:24 2012] [info] mod_wsgi (pid=30262): Attach interpreter ''.
[Mon Nov 12 18:05:24 2012] [info] mod_wsgi (pid=30261): Attach interpreter ''.
[Mon Nov 12 18:05:24 2012] [info] mod_wsgi (pid=30263): Attach interpreter ''.
[Mon Nov 12 18:05:24 2012] [info] mod_wsgi (pid=30264): Attach interpreter ''.
[Mon Nov 12 18:05:28 2012] [info] mod_wsgi (pid=30270): Initializing Python.
[Mon Nov 12 18:05:28 2012] [info] mod_wsgi (pid=30270): Attach interpreter ''.
[Mon Nov 12 18:07:50 2012] [info] mod_wsgi (pid=30311): Initializing Python.
[Mon Nov 12 18:07:50 2012] [info] mod_wsgi (pid=30311): Attach interpreter ''.
[Mon Nov 12 18:07:51 2012] [info] [client 24.143.104.168] (32)Broken pipe: core_output_filter: writing data to the network
[Mon Nov 12 18:10:44 2012] [info] [client 180.76.5.64] (104)Connection reset by peer: core_output_filter: writing data to the network
[Mon Nov 12 18:11:26 2012] [info] mod_wsgi (pid=30356): Initializing Python.
[Mon Nov 12 18:11:26 2012] [info] mod_wsgi (pid=30356): Attach interpreter ''.

我觉得它可能与Python路径有关。只是一个猜测。它绝对看起来像Python一直在崩溃。

/home
  /myproject
    /public_html (server document root)
    /django_proj
      /myproject (django project root)
        settings.py
        other files and app directories for this django project
        /apache
          wsgi.py
          django.wsgi

以下是httpd.conf的相关部分:

<VirtualHost *:80>

    ServerName myproject.mysite.net
    ServerAdmin myemail@abc.com

    DocumentRoot /home/myproject/django_proj/myproject

    <Directory /home/myproject/django_proj/myproject>
    AllowOverride All
    Order allow,deny
    Allow from all
    </Directory>

    WSGIDaemonProcess myproject.mysite.net processes=1 threads=1 display-name=%{GROUP}
    WSGIProcessGroup myproject.mysite.net
    WSGIApplicationGroup %{GLOBAL}

    WSGIScriptAlias / /home/myproject/django_proj/myproject/apache/django.wsgi

    <Directory /home/myproject/django_proj/myproject/apache>
    Order allow,deny
    Allow from all
    </Directory>

</VirtualHost>

这是我的wsgi.py:

import os

path = '/home/myproject/django_proj'
if path not in sys.path:
    sys.path.append(path)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")

# This application object is used by the development server
# as well as any WSGI server configured to use this file.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

这是我的django.wsgi:

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]

我也试图将其作为URL“myproject.mysite.net”而不是“mysite.net”来托管。不确定我是否一直这样做。

1 个答案:

答案 0 :(得分:1)

实际问题是什么?您提出请求时实际上是否收到错误。

日志输出看起来很正常。所有单独的进程都是因为Python也在Apache子工作进程中初始化。设置:

WSGIRestrictEmbedded On

他们会离开,应该只看到一个过程。

有关该指令的说明,请参阅:

http://blog.dscpl.com.au/2009/11/save-on-memory-with-modwsgi-30.html

BTW,使用'processes = 1 threads = 1'似乎是一个糟糕的选择。一次只能处理一个请求。