nginx + uwsgi + python: 502 Bad Gateway


[現象]

  • nginx と uwsgi を起動したが「502 Bad Gateway」
  • nginxからプロキシはうまくいっているがuwsgiが受取れていないようだ

[原因]

  • カーネル値調整不足

  • ログ確認
//uWSGIログ
*** Starting uWSGI 2.0.9 (64bit) on [Fri May 29 19:34:16 2015] ***
compiled with version: 4.4.7 20120313 (Red Hat 4.4.7-11) on 27 May 2015 15:04:13
os: Linux-2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014
nodename: webap-01
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /etc/uwsgi
detected binary path: /opt/venv/app/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
setgid() to 99
setuid() to 498
chdir() to /opt/app/
your processes number limit is 20480
your memory page size is 4096 bytes
detected max file descriptor number: 65536
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
Listen queue size is greater than the system max net.core.somaxconn (1024).
  • 「net.core.somaxconn」が足りないようだ。
# grep listen /etc/uwsgi.yaml
  listen: 16384
# vi /etc/sysctl.conf
net.core.somaxconn = 20480
# sysctl -w net.core.somaxconn=20480
# sysctl net.core.somaxconn
# /etc/rc.d/init.d/uwsgi restart
//uWSGIログ

*** Starting uWSGI 2.0.9 (64bit) 
:
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 26131)
spawned uWSGI worker 1 (pid: 26132, cores: 1)
spawned uWSGI worker 2 (pid: 26133, cores: 1)
spawned uWSGI worker 3 (pid: 26134, cores: 1)
spawned uWSGI worker 4 (pid: 26135, cores: 1)

起動した ε-(´∀`*)ホッ