【发布时间】:2015-08-05 19:54:10
【问题描述】:
我在解决此问题时遇到了困难。我有一个在 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 的调试在这里也没有什么用处。
【问题讨论】:
-
应用程序对数据库的访问通常是通过另一个端口,而不是通过Apache。生产环境中SQL Server地址是否配置正确?
-
感谢您的回复,aldux。我正在使用 freetds 通过端口 1433 访问 SQL Server。此设置对于我的开发和生产环境是相同的,但我会尽快在这里再次检查。
标签: python sql-server django apache pymssql