尝试通过Apache连接到数据库时,Django应用程序会挂起 [英] Django app hangs when attempting to connect to database via Apache
问题描述
我无法解决这个问题。我有一个在Ubuntu 14.04服务器上运行的Django应用程序(Apache 2.4和Python 3.4的mod_wsgi)。它通过pymssql连接到SQL Server。
I am having difficulty troubleshooting this issue. I have a Django app running on an Ubuntu 14.04 server (with Apache 2.4 and mod_wsgi for Python 3.4). It connects to SQL Server via pymssql.
在开发中,应用程序可以正常工作。我查询数据库,数据库返回预期的结果。
In development, the app works fine. I query the database, and the database returns the expected results.
然而,在生产(在Apache用户下),该脚本挂在数据库查询的确切位置是做的只要浏览器窗口打开,我的浏览器(Chrome或Firefox)会显示一个旋转轮。
In production (under the Apache user), however, the script hangs at the exact point that a database query is made. My browser (Chrome or Firefox) shows a spinning wheel that continues to spin as long as the browser window is open.
我的 apache2.conf
文件:
ServerName localhost
# WSGIDaemonProcess application
WSGIPythonPath /home/production_code/python3env/lib/python3.4/site-packages:/home/production_code/school
# WSGIProcessGroup application
WSGIScriptAlias / /home/production_code/school/school/wsgi.py
# Python virtualenv home
WSGIPythonHome /home/production_code/python3env
# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf
以下在我的 sites-enabled / 000-default.conf
file: / p>
And the following in my sites-enabled/000-default.conf
file:
<VirtualHost *:80>
ServerAdmin *****@school.edu
ServerName localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /static/ /home/production_code/school/static/
<Directory /home/production_code/school/>
Require all granted
</Directory>
<Directory /home/production_code/school/>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory /home/production_code/school/static>
Require all granted
</Directory>
</VirtualHost>
<在这种情况下,Apache错误日志和访问日志并不特别有用,因为对请求的响应不会被渲染。类似地,Django调试在这里也没有用。
Does anyone have any idea what might be causing this or how I might troubleshoot this? The Apache error logs and access logs are not particularly helpful in this situation, since a response to the request is never rendered. Similarly, Django debugging is also not useful here.
推荐答案
而不是:
# WSGIDaemonProcess application
WSGIPythonPath /home/production_code/python3env/lib/python3.4/site-packages:/home/production_code/school
# WSGIProcessGroup application
使用:
WSGIDaemonProcess application python-path=/home/production_code/python3env/lib/python3.4/site-packages:/home/production_code/school
WSGIProcessGroup application
WSGIApplicationGroup %{GLOBAL}
其中的一个关键部分是 WSGIApplicationGroup
指令,其设置为%{GLOBAL}
。
A key part of this is the WSGIApplicationGroup
directive, with it being set to %{GLOBAL}
.
这是为了避免错误的第三方扩展模块Python不能在子解释器中工作,并且可能会因死锁或崩溃而失败。
This is to get around faulty third party extension modules for Python that don't work in sub interpreters and which can fail with a dead lock or crash.
请参阅:
- https://code.google.com/p/modwsgi/wiki/ApplicationIssues#Python_Simplified_GIL_State_API
还建议您返回使用守护进程模式。使用嵌入式模式通常不是一个好主意。
It is also recommend you go back to using daemon mode. It is generally not a good idea to use embedded mode.
- http://blog.dscpl.com.au/2012/10/why-are-you-using-embedded-mode-of.html
这篇关于尝试通过Apache连接到数据库时,Django应用程序会挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!