1

我一直坚持将我的 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”。也不确定我是否做对了。

4

1 回答 1

1

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

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

WSGIRestrictEmbedded On

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

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

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

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

于 2012-11-13T10:30:56.890 回答