尝试通过Apache连接到数据库时,Django应用程序挂起

解决此问题时遇到问题。 我有一个运行在Ubuntu 14.04服务器上的Django应用程序(Apache 2.4和Python 3.4的mod_wsgi)。 它通过pymssql连接到SQL Server。

在开发中,应用程序工作正常。 我查询数据库,数据库返回预期的结果。

然而,在生产(在Apache用户下),脚本在数据库查询的确切位置挂起。 我的浏览器(Chrome或Firefox)显示只要浏览器窗口打开,旋转轮就会继续旋转。

我在我的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文件中:

 <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的debugging在这里也没有用。

代替:

 # 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}

这是为了解决Python错误的第三方扩展模块,这些扩展模块在子解释器中不起作用,并且可能因失锁或崩溃而失败。

看到:

还建议您回到使用守护进程模式。 使用嵌入模式通常不是一个好主意。