我有一个连接谷歌应用程序发送电子邮件的Django应用程序.但是,几天前我开始收到"由同行重置连接"错误.有时候它有效,有时候不行......我找不到任何理由来证明什么时候不行......我正在使用nginx和uwsgi.任何人都可以帮助我了解最新情况以及解决方法吗?
这个应用程序运行超过1个月,刚刚开始出现此错误.
这是日志:
Traceback (most recent call last):
File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/core/handlers/base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/utils/decorators.py", line 93, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/contrib/auth/views.py", line 155, in password_reset
form.save(**opts)
File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/contrib/auth/forms.py", line 147, in save
t.render(Context(c)), from_email, [user.email])
File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/core/mail/__init__.py", line 61, in send_mail
connection=connection).send()
File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/core/mail/message.py", line 251, in send
return self.get_connection(fail_silently).send_messages([self])
File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/core/mail/backends/smtp.py", line 90, in send_messages
self.close()
File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/core/mail/backends/smtp.py", line 58, in close
self.connection.quit()
File "/usr/lib/python2.6/smtplib.py", line 730, in …
Run Code Online (Sandbox Code Playgroud) 我正在使用Supervisord来管理服务器上的uwsgi进程,我遇到了这两个选项:environment
以及directory
使用Supervisord运行程序.
我看看文档,但仍然不确定他们到底做了什么.为了澄清,这里的上下文是我正在使用uwsgi运行web2py应用程序.在uwsgi的配置中,我已经设置了PYTHONPATH和它应该运行的virtualenv.
有人可以解释这两个选项的用途,如何在必要时设置它们?
这是一个数据流:http < - > nginx < - > uWSGI < - > python webapp
我想在nginx中有http2uwsgi传输,在uWSGI中有uwsgi2http.
如果我想直接调用uWSGI来测试webapp中的API,该怎么办?
实际上我正在使用金字塔.只需在.ini中配置[uwsgi]并运行uWSGI.但我想测试uWSGI是否正常保持webapp功能,http不能直接访问uWSGI套接字.
Stack:nginx,uwsgi,django
uwsgitop和top都显示uwsgi工作者是空闲的,而nginx错误日志表示上游超时.
我认为一些请求需要很多资源,比如等待db或cache,而其他的则不需要.在检查超时请求后,他们中的大多数都没有贪婪.任何形式的请求都已超时.
那么,如果其他人真的很忙,为什么nginx没有将请求播种到空闲的?为什么uwsgi大师只是让别人忙,其他人闲着?
环境:CentOS6.4,python2.6我创建了一个virtualenv(envflask)并激活它,然后pip安装烧瓶,一切都还可以!但是在创建了另一个virtualenv(envuwsgi)并激活它后,我没有pip install uwsgi,错误消息是:
...
plugins/python/python_plugin.c:1731: ?????????‘<erroneous-expression>’??????
plugins/python/python_plugin.c:1731: ?????????
plugins/python/python_plugin.c: ???‘uwsgi_python_harakiri’?:
plugins/python/python_plugin.c:1737: ???‘struct uwsgi_python’????‘tracebacker’???
plugins/python/python_plugin.c:1740: ???‘struct uwsgi_python’????‘tracebacker’???
plugins/python/python_plugin.c:1740: ?????‘uwsgi_concat2’?? 1 ????????????????
plugins/python/../../uwsgi.h:2733: ???????‘char *’????????‘struct uwsgi_option *’
plugins/python/python_plugin.c: ???‘uwsgi_python_logger’?:
plugins/python/python_plugin.c:1768: ???‘struct uwsgi_python’????‘gil_get’???
plugins/python/python_plugin.c:1768: ?????????‘<erroneous-expression>’??????
plugins/python/python_plugin.c:1768: ?????????
plugins/python/python_plugin.c:1771: ???‘PyObject’???(??????????)
plugins/python/python_plugin.c:1771: ???‘py_logging’???(??????????)
plugins/python/python_plugin.c:1771: ???????? * ???(‘struct uwsgi_option *’?‘struct uwsgi_option *’)??
plugins/python/python_plugin.c:1771: ?????????
plugins/python/python_plugin.c:1773: ???‘py_logging_dict’???(??????????)
plugins/python/python_plugin.c:1773: ???????? * ???(‘struct uwsgi_option *’?‘struct uwsgi_option *’)??
plugins/python/python_plugin.c:1773: ?????????
plugins/python/python_plugin.c:1775: ???‘py_getLogger’???(??????????)
plugins/python/python_plugin.c:1775: ???????? * ???(‘struct uwsgi_option *’?‘struct uwsgi_option *’)??
plugins/python/python_plugin.c:1775: ?????????
plugins/python/python_plugin.c:1777: ???‘py_getLogger_args’???(??????????)
plugins/python/python_plugin.c:1777: ???????? * ???(‘struct uwsgi_option *’?‘struct …
Run Code Online (Sandbox Code Playgroud) 首先,一点背景.我在emperor模式下在uWSGI下运行一个应用程序.uWSGI命令行:
uwsgi --master --emperor /etc/uwsgi --die-on-term --uid uwsgi --gid uwsgi
Run Code Online (Sandbox Code Playgroud)
我的应用程序的INI文件位于/ etc/uwsgi中,并在uWSGI启动时成功找到.我的应用程序的uwsgi和日志记录配置部分:
[uwsgi]
socket = /tmp/uwsgi.sock
master = true
processes = 8
threads = 4
harakiri = 60
harakiri-verbose = true
limit-post = 52428800
post-buffering = 8192
listen = 256
max-requests = 1000
buffer-size = 32768
no-orphans = true
logto = /var/log/uwsgi/my_app.log
log-slow = 1000
virtualenv = /usr/local/python/my_app
paste = config:%p
[loggers]
keys = root, my_app
[handlers]
keys = console
[formatters]
keys = generic
[logger_root]
level = WARN
handlers = …
Run Code Online (Sandbox Code Playgroud) 我uWsgi
用来部署我的django
网站是我的uWsgi.ini
:
[uwsgi]
socket=/var/run/uwsgi.sock
virtualenv=/root/edupalm/env/
chdir=/root/edupalm/edupalm
master=True
workers=8
pidfile=/var/run/uwsgi-master.pid
max-requests=5000
module=edupalm.wsgi:application
Run Code Online (Sandbox Code Playgroud)
并使用nginx,这是我的配置:
server {
listen 9000;
server_name 162.243.146.127;
access_log /var/log/nginx/edupalm_access.log;
error_log /var/log/nginx/edupalm_error.log;
location /static/ {
alias /root/edupalm/edupalm/static/;
}
location / {
uwsgi_pass unix:///var/run/uwsgi.sock;
}
}
Run Code Online (Sandbox Code Playgroud)
但我有 502 Bad Gateway
这是日志:
nginx的:
2013/11/26 08:31:09 [error] 1758#0: *57 upstream prematurely closed connection while reading response header from upstream, client: 197.160.112.183, server: 162.243.146.127, request: "GET /admin HTTP/1.1", upstream: "uwsgi://unix:///var/run/uwsgi.sock:", host: "162.243.146.127:9000"
Run Code Online (Sandbox Code Playgroud)
uwsgi:
-- unavailable modifier requested: 0 -- …
Run Code Online (Sandbox Code Playgroud) 我已经尝试了一些uwsgi教程,但无法在我的浏览器中运行一个简单的python脚本.我已经通读了这个(http://uwsgi-docs.readthedocs.org/en/latest/WSGIquickstart.html)和这个(https://www.digitalocean.com/community/articles/how-to-deploy-python- wsgi-applications-using-uwsgi-web-server-with-nginx)和其他人,但由于某种原因无法运行简单的uwsgi应用程序.我目前没有通过网络服务器,只是uwsgi本身.
我有以下wsgi.py:
def application(env, start_response):
start_response('200 OK', [('Content-Type', 'text/html')])
return ["Hello!"]
Run Code Online (Sandbox Code Playgroud)
我跑:
uwsgi --socket 127.0.0.1:8080 --chdir /my/program/path --pp .. -w wsgi
Run Code Online (Sandbox Code Playgroud)
产生以下输出(看起来很有希望):
*** Starting uWSGI 2.0.3 (64bit) on [Mon Apr 14 12:51:32 2014] ***
compiled with version: 4.6.3 20120306 (Red Hat 4.6.3-2) on 14 April 2014 12:01:33
os: Linux-3.1.0-7.fc16.x86_64 #1 SMP Tue Nov 1 21:10:48 UTC 2011
nodename: ip-10-252-98-215
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /usr/oai/icscada/www
detected …
Run Code Online (Sandbox Code Playgroud) 我的应用程序使用 nginx 和 uwsgi (python) 运行。我的目标是要断开连接(如解释在这里),例如,当Python应用程序决定这样做。
是否有一个 nginx 参数来“拦截”类似的上游错误proxy_intercept_errors
?
根据这个答案,
我的 nginx 配置:
location / {
uwsgi_pass myapp;
include uwsgi_params;
uwsgi_buffering on;
uwsgi_buffer_size 8k;
uwsgi_connect_timeout 800;
uwsgi_read_timeout 800;
uwsgi_send_timeout 800;
proxy_intercept_errors on;
error_page 420 =444 @foo;
}
location @foo {
return 444;
}
Run Code Online (Sandbox Code Playgroud)
我尝试了所有可能的组合,我可以想到有/没有proxy_intercept_errors
,error_page
但无论我如何配置 nginx,当我返回420 Enhance your calm
(或任何其他错误代码,显然)时,它都会直接传递给客户端。
这个答案建议使用,proxy_next_upstream
但这意味着使用proxy_pass
而不是uwsgi_pass
. 我需要使用,uwsgi_pass
因为我需要将某些参数传递给 python 应用程序。
我有一个带有 virtualenv的Flask
应用程序/find_bili_user/app.py
/python_envs/env1/
,
app.py
:
from flask import Flask, jsonify, request, make_response
from biliuser import getdanmu
app = Flask('__name__')
@app.route('/find_bili_user.json', methods=['GET'])
def get_user():
avid = request.args.get('avid')
if not avid or not avid.isdigit():
return invalid_avid()
else:
message = getdanmu(int(avid))
if not message:
return failed()
else:
response = jsonify(message)
return response
@app.errorhandler(400)
def invalid_avid():
return make_response(jsonify({'error': 'invalid avid.'}), 400)
@app.errorhandler(400)
def failed():
return make_response(jsonify({'error': 'failed parsing comments.'}), 400)
if __name__ == '__main__':
app.run()
Run Code Online (Sandbox Code Playgroud)
我的 uwsgi 配置:
[uwsgi]
chdir …
Run Code Online (Sandbox Code Playgroud)