简体   繁体   English

网关超时在Apache上使用Django和mod_wsgi

[英]Gateway Timeout Using Django on Apache with mod_wsgi

I'm having a problem getting Apache to reply properly. 我在让Apache正确回复时遇到问题。 I'm getting a browser error: Gateway Timeout: The gateway did not receive a timely response from the upstream server or application. 我收到浏览器错误: Gateway Timeout: The gateway did not receive a timely response from the upstream server or application.

I know the application is connecting through mod_wsgi to the Django layer, as I've verified queries are occurring in PostgreSQL when the connection occurs, from the Wagtail CMS's middleware running. 我知道应用程序通过mod_wsgi连接到Django层,因为我已经验证了在连接发生时PostgreSQL中发生的查询,来自Wagtail CMS的中间件运行。

The system is running RHEL 7.1, Apache 2.4.6, and mod_wsgi 4.4.21 with Python 3.4 and Django 1.8. 系统运行RHEL 7.1,Apache 2.4.6和带有Python 3.4和Django 1.8的mod_wsgi 4.4.21。

Here's the error in the Apache log: 这是Apache日志中的错误:

[Thu Jan 07 13:25:54.554395 2016] [wsgi:error] [pid 17128] [client 128.91.91.123:50664] Timeout when reading response headers from daemon process 'my_classroom-https': /var/www/html/my_classroom/my_classroom/wsgi.py

Here's wsgi.py: 这是wsgi.py:

import os, sys
from socket import gethostname
from django.core.wsgi import get_wsgi_application

sys.path.append(os.sep.join(os.path.abspath(__file__).split(os.sep)[:-2]))

# cpl == Core, Production, Linux..
if(gethostname()[:3]) == 'cpl':
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_classroom.settings.prod")
# csl == Core, Staging, Linux.
elif(gethostname()[:3]) == 'csl':
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_classroom.settings.stage")
# else use dev settings.
# cdl == Core, Development, Linux. vag == Vagrant.
else:
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_classroom.settings.dev")

application = get_wsgi_application()

And here's the relevant portion of the Apache config: 这是Apache配置的相关部分:

LoadModule wsgi_module modules/mod_wsgi.so
LoadModule ssl_module modules/mod_ssl.so

WSGISocketPrefix /var/run/wsgi

NameVirtualHost *:443
Listen 443
<VirtualHost *:443>

  ServerName my-python-dev.school.edu
  ErrorLog /var/www/logs/classroom-apache-errors.log

  SSLENGINE on

  SSLCertificateFile /etc/pki/tls/certs/localhost.crt
  SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
  SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
  SSLProtocol all -SSLv2

  WSGIApplicationGroup %{GLOBAL}
  WSGIDaemonProcess my_classroom-https python-home=/var/www/virtualenvs/my_classroom request-timeout=600
  WSGIScriptAlias /classroom /var/www/html/my_classroom/my_classroom/wsgi.py process-group=my_classroom-https
  WSGIProcessGroup my_classroom-https
  Alias /classroom/static/ /var/www/html/my_classroom/static/

  LogLevel info
</VirtualHost>

I've tried a few few things, including increasing the request-timeout parameter of the WSGIDaemonProcess directive to be 600 seconds instead of 60, but it still seems to timeout right around 60 seconds. 我已经尝试了一些方法,包括将WSGIDaemonProcess指令的request-timeout参数增加到600秒而不是60秒,但它似乎仍然在60秒左右超时。

Any ideas or help would be greatly appreciated. 任何想法或帮助将不胜感激。 Thanks. 谢谢。

I got this working. 我得到了这个工作。 The problem was a secondary database definition (not default ) which couldn't connect to the server. 问题是辅助数据库定义(非default )无法连接到服务器。 There was no indication of this anywhere in the logs, unfortunately. 不幸的是,日志中没有任何迹象表明这一点。 This is a tough error to debug. 这是一个很难调试的错误。

Here's some steps I'd take next time I see this error: 这是我下次看到这个错误时会采取的一些步骤:

  • Take a very deep breath and relax! 深呼吸,放松一下!
  • Confirm if any activity is happening in the database at all for the request. 确认请求中是否在数据库中发生任何活动。
  • Make sure you can connect to all services needed by telnet ( telnet mypostgresserver.domain.com 5432 , telnet ldap.myprivate.network 636 ), and that they're not hanging. 确保您可以连接到telnet所需的所有服务( telnet mypostgresserver.domain.com 5432telnet ldap.myprivate.network 636 ),并且它们没有挂起。
  • Modify the settings files, excluding anything possible (middleware, optional apps, backends other than ModelBackend, etc) 修改设置文件,排除任何可能的内容(中间件,可选应用程序,ModelBackend以外的后端等)
  • Failing that, start commenting out segments of the settings files, to see if you can get a less cryptic response. 如果做不到这一点,请开始评论设置文件的各个部分,看看是否可以得到一个不那么神秘的响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM