uwsgi 和 nginx 上游上的 Web2py 在读取上游时超时(110:连接超时)



我已经在NGINX上部署了我的应用程序。而我的错误.log充满了:

upstream timed out (110: Connection timed out) while reading upstream, client: 10.107.46.176, server: myApp, request: "GET /myApp/Home/index.load HTTP/1.1", upstream: "uwsgi://unix:///tmp/web2py.socket:", host: "myApp.eng.home.com", referrer: "http://myApp.eng.home.com/"

我部署了一个Postgres DB。这就是index.htmlpage的外观:

<div class="clicks">{{=LOAD(c='Home',f='index',extension='load',ajax=True,timeout=30000,times=3)}}
{{pass}}
</div>

这是 index.load 页面:

{{=numHits}}

这是我的 Home.py 控制器:

def index():
numHits = db(db.opStatus.id > 0).count()
return dict(numHits=numHits)

这与火箭服务器一起工作正常,仅在 NGINX 中失败。KInd帮助我。

web2py.ini

$ cat /etc/uwsgi/web2py.ini
[uwsgi]
socket = /tmp/web2py.socket
pythonpath = /home/www-data/web2py/
mount = /=wsgihandler:application
processes = 4
master = true
harakiri = 60
reload-mercy = 8
cpu-affinity = 1
stats = /tmp/stats.socket
max-requests = 2000
limit-as = 512
reload-on-as = 256
reload-on-rss = 192
uid = www-data
gid = www-data
touch-reload = /home/www-data/web2py/routes.py
cron = 0 0 -1 -1 -1 python /home/www-data/web2py/web2py.py -Q -S myApp -M -R scripts/sessions2trash.py -A -o
no-orphans = true

UWSGI-Emperor.conf

/etc/init$ cat uwsgi-emperor.conf
# Emperor uWSGI script
description "uWSGI Emperor"
start on runlevel [2345]
stop on runlevel [06]
##
#remove the comments in the next section to enable static file compression for the welcome app
#in that case, turn on gzip_static on; on /etc/nginx/nginx.conf
##
#pre-start script
#    python /home/www-data/web2py/web2py.py -S welcome -R scripts/zip_static_files.py
#    chown -R www-data:www-data /home/www-data/web2py/*
#end script
respawn
exec uwsgi --master --die-on-term --emperor /etc/uwsgi --logto /var/log/uwsgi/uwsgi.log

皇帝.UWSGI.服务

cat /etc/systemd/system/emperor.uwsgi.service
[Unit]
Description = uWSGI Emperor
After = syslog.target
[Service]
ExecStart = /usr/local/bin/uwsgi --ini /etc/uwsgi/web2py.ini
RuntimeDirectory = uwsgi
Restart = always
KillSignal = SIGQUIT
Type = notify
StandardError = syslog
NotifyAccess = all
[Install]
WantedBy = multi-user.target

我通过以下方式启动服务: 须藤服务天皇.UWSGI开始

由于我的声誉不允许评论您的问题,因此我不得不稍微滥用回答部分,希望不要遇到任何麻烦:

自从我使用 NGINX 部署我的 web2py 应用程序以来,所有问题都基于 uWSGI 的错误配置。因此,我的第一个建议是检查您的uWSGI安装和配置。特别是检查emperor.uwsgi.service,uwsgi/web2py.ini和uwsgi-emperor.conf。

此外,您可能有另一个web2py安装目录,默认情况下假定为"/home/www-data/web2py。在这种情况下,你必须适应nginx/sites-available/web2py。

最后,检查已安装web2py的用户。此用户必须在nginx/nginx.conf中正确配置

希望这些提示可以帮助您解决问题。如果没有,请如上所述发布您的配置文件。

附加信息:

感谢您提供配置文件。我已经将这些与我的配置进行了比较,看起来不错。

但我有点困惑你手动启动皇帝。在我的配置中,这是由nginx服务器完成的,如在/etc/nginx/sites-available/web2py中配置的那样,如下所示:

# file /etc/nginx/sites-available/web2py
server {
listen          80;
server_name     $hostname;
###to enable correct use of response.static_version
location ~* ^/(w+)/static(?:/_[d]+.[d]+.[d]+)?/(.*)$ {
alias /home/www-data/web2py/applications/$1/static/$2;
expires max;
### if you want to use pre-gzipped static files (recommended)
### check scripts/zip_static_files.py and remove the comments
# include /etc/nginx/conf.d/web2py/gzip_static.conf;
}
###
###if you use something like myapp = dict(languages=['en', 'it', 'jp'], default_language='en') in your routes.py
#location ~* ^/(w+)/(en|it|jp)/static/(.*)$ {
#    alias /home/www-data/web2py/applications/$1/;
#    try_files static/$2/$3 static/$3 =404;
#}
###
location / {
#uwsgi_pass      127.0.0.1:9001;
uwsgi_pass      unix:///tmp/web2py.socket;
include         uwsgi_params;
uwsgi_param     UWSGI_SCHEME $scheme;
uwsgi_param     SERVER_SOFTWARE    nginx/$nginx_version;
###remove the comments to turn on if you want gzip compression of your pages
# include /etc/nginx/conf.d/web2py/gzip.conf;
### end gzip section
### remove the comments if you use uploads (max 10 MB)
#client_max_body_size 10m;
###
}
}
server {
listen 443 default_server ssl;
server_name     $hostname;
ssl_certificate         /etc/nginx/ssl/web2py.crt;
ssl_certificate_key     /etc/nginx/ssl/web2py.key;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_ciphers ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
keepalive_timeout    70;
location / {
#uwsgi_pass      127.0.0.1:9001;
uwsgi_pass      unix:///tmp/web2py.socket;
include         uwsgi_params;
uwsgi_param     UWSGI_SCHEME $scheme;
uwsgi_param     SERVER_SOFTWARE    nginx/$nginx_version;
###remove the comments to turn on if you want gzip compression of your pages
# include /etc/nginx/conf.d/web2py/gzip.conf;
### end gzip section
### remove the comments if you want to enable uploads (max 10 MB)
#client_max_body_size 10m;
###
}
###to enable correct use of response.static_version
location ~* ^/(w+)/static(?:/_[d]+.[d]+.[d]+)?/(.*)$ {
alias /home/www-data/web2py/applications/$1/static/$2;
expires max;
### if you want to use pre-gzipped static files (recommended)
### check scripts/zip_static_files.py and remove the comments
# include /etc/nginx/conf.d/web2py/gzip_static.conf;
}
###
}

请特别注意两条线

uwsgi_pass      unix:///tmp/web2py.socket;

我将.socket标记为特殊,但不记得为什么。也许我在安装脚本中错过了它,不确定。

这能解决你的问题吗?

此致敬意 克莱门斯

最新更新