wsgi 启动 - 为什么有两个相同的进程? [英] wsgi startup - why two identical processes?

查看:45
本文介绍了wsgi 启动 - 为什么有两个相同的进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下配置:

虚拟主机:

<VirtualHost *:80>
    ServerAdmin rok@localhost
    ServerName lh.test.com

    WSGIScriptAlias / /home/user/myapp/src/wsgi.py application-group='%{GLOBAL}' process-group='%{GLOBAL}'
    WSGIDaemonProcess lh.test.com processes=1 threads=1 display-name=%{GROUP}

    <Directory /home/user/myapp/src>
      <Files wsgi.py>
        Order deny,allow
        Require all granted
      </Files>
      Options All
      AllowOverride All
      Require all granted
    </Directory>

    Alias /static /home/user/myapp/src/static

    ErrorLog /var/log/apache2/lh.test.com-error.log
    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel debug
    CustomLog /var/log/apache2/lh.test.com-access.log combined

</VirtualHost>

wsgi.py:

from __future__ import unicode_literals
import os, signal, sys

sys.path.append('/home/user/apps/django-trunk')
sys.path.insert(0, '/home/user/myapp/src')

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

print 'starting up wsgi application...'
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

当我启动 apache 时,它​​总是出于某种原因启动两个相同的 wsgi 进程:

When I start apache, it always starts two identical wsgi processes for some reason:

apache 日志:

Mon Jan 06 21:17:02.895219 2014] [mpm_event:notice] [pid 27628:tid 140594224048000] AH00489: Apache/2.4.6 (Ubuntu) mod_wsgi/3.4 Python/2.7.5+ configured -- resuming normal operations
[Mon Jan 06 21:17:02.895287 2014] [core:notice] [pid 27628:tid 140594224048000] AH00094: Command line: '/usr/sbin/apache2'
[Mon Jan 06 21:17:02.905771 2014] [:error] [pid 27632:tid 140594224048000] starting up wsgi application...
[Mon Jan 06 21:17:02.909542 2014] [:error] [pid 27633:tid 140594224048000] starting up wsgi application...

和 ps 辅助:

root     27628  0.0  0.0  84196  3100 ?        Ss   21:17   0:00 /usr/sbin/apache2 -k start
www-data 27632  0.1  0.3 470984 24648 ?        Sl   21:17   0:00 /usr/sbin/apache2 -k start
www-data 27633  0.1  0.3 470984 24648 ?        Sl   21:17   0:00 /usr/sbin/apache2 -k start

知道为什么会这样吗?

推荐答案

您的 WSGIScriptAlias 指令错误:

You have the WSGIScriptAlias directive wrong:

WSGIScriptAlias / /home/user/myapp/src/wsgi.py application-group='%{GLOBAL}' process-group='%{GLOBAL}'

应该是:

WSGIScriptAlias / /home/user/myapp/src/wsgi.py application-group='%{GLOBAL}' process-group='lh.test.com'

结果是您的应用程序不是在守护程序模式下运行,而是在嵌入式模式下运行,因此在 Apache 子工作进程中运行.因此,您看到的进程数量取决于 Apache MPM 设置.

The result is that your application isn't running in daemon mode but embedded mode, and so is running in the Apache child worker processes. As such how many processes you see is going to be up to the Apache MPM settings.

更改该指令并设置:

WSGIRestrictEmebedded On

这将关闭在 Apache 子工作进程中运行的东西的能力,如果你填满你的配置并且没有委派应用程序在守护进程组中正确运行,则会导致错误.

This will turn off the ability for stuff to run in the Apache child worker process and cause an error if you stuff up your configuration and don't delegate an application to run in the daemon process group properly.

另请阅读:

这篇关于wsgi 启动 - 为什么有两个相同的进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆