wsgi startup - why two identical processes?

 ̄綄美尐妖づ 提交于 2019-12-24 17:10:06

问题


I have the following config:

virtualhost:

<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()

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

apache log:

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...

and ps aux:

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

any idea why that is so?


回答1:


You have the WSGIScriptAlias directive wrong:

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

It should be:

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

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.

Change that directive and also set:

WSGIRestrictEmebedded On

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.

Also go read:

  • http://blog.dscpl.com.au/2012/10/why-are-you-using-embedded-mode-of.html


来源:https://stackoverflow.com/questions/20958553/wsgi-startup-why-two-identical-processes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!