在Windows上使用mod_wsgi时加载时间不稳定

时间:2015-07-28 06:00:31

标签: python django windows apache mod-wsgi

我的系统安装了以下版本的软件:

我使用 virtualenv 两个Django项目创建了两个环境(只是默认它工作了!页面)一个托管在one.local.com(VirtualHost)上,另一个托管在two.local.com(VirtualHost)上。下面的代码是Apache的 httpd-vhost.conf 文件的VirtualHost配置。

<VirtualHost *:80>
  WSGIApplicationGroup %{ENV:ONE_GROUP}
  ServerName one.local.com
  ServerAdmin admin@example.com
  ErrorLog "D:/_pythonDev/Projects/logs/one.local.com-error.log"
  CustomLog "D:/_pythonDev/Projects/logs/one.local.com-access.log" common

  WSGIScriptAlias / "D:/_pythonDev/Projects/Project1/Project1/wsgi.py" application-group=%{ENV:ONE_GROUP}
  # I also tried WSGIImportScript
  <Directory "D:/_pythonDev/Projects/Project1/Project1">
    <Files wsgi.py>
      Require all granted
    </Files>
  </Directory>

  Alias /favicon.ico "D:/_pythonDev/Projects/Project1/static/favicon.ico"
  Alias /static/ "D:/_pythonDev/Projects/Project1/static/"
  <Directory "D:/_pythonDev/Projects/Project1/static">
    Require all granted
  </Directory>
</VirtualHost>

<VirtualHost *:80>
  WSGIApplicationGroup %{ENV:TWO_GROUP}
  ServerName two.local.com
  ServerAdmin admin@example.com
  ErrorLog "D:/_pythonDev/Projects/logs/two.local.com-error.log"
  CustomLog "D:/_pythonDev/Projects/logs/two.local.com-access.log" common

  WSGIScriptAlias / "D:/_pythonDev/Projects/Project2/Project2/wsgi.py" application-group=%{ENV:TWO_GROUP}

  <Directory "D:/_pythonDev/Projects/Project2/Project2">
    <Files wsgi.py>
      Require all granted
    </Files>
  </Directory>

  Alias /favicon.ico "D:/_pythonDev/Projects/Project2/static/favicon.ico"
  Alias /static/ "D:/_pythonDev/Projects/Project2/static/"
  <Directory "D:/_pythonDev/Projects/Project2/static">
    Require all granted
  </Directory>
</VirtualHost>

以下是one.local.com的 wsgi.py

import os
import sys
import site

site.addsitedir("D:/_pythonDev/env/env1/Lib/site-packages")

sys.path.append("D:/_pythonDev/Projects/Project1/Project1")
sys.path.append("D:/_pythonDev/Projects/Project1")

activate_env_file = "D:/_pythonDev/env/env1/Scripts/activate_this.py"

exec(open(activate_env_file).read(), dict(__file__=activate_env_file))

from django.core.wsgi import get_wsgi_application

os.environ["DJANGO_SETTINGS_MODULE"] = "Project1.settings"

application = get_wsgi_application()

问题:

  • 加载时间不稳定大约需要10秒。

需要回答:

  • 加载时间不稳定的原因。
  • 解决问题的答案。

0 个答案:

没有答案