折腾:
期间,
(SIPEvents) ➜ SIPEvents cat app.py from flask import Flask app = Flask(__name__) @app.route(“/”) def hello(): return “Hello Flask and uWSGI!” if __name__ == “__main__”: app.run(host=’0.0.0.0′, port=8080) |
在启动了uwsgi:
➜ ~ workon SIPEvents (SIPEvents) ➜ ~ cd /usr/share/nginx/html/SIPEvents (SIPEvents) ➜ SIPEvents ll total 100K -rw-r–r– 1 root root 181 Aug 18 15:42 app.py -rw-r–r– 1 root root 438 Aug 18 15:46 app.pyc -rw-r–r– 1 root root 62 Aug 17 17:27 manage.py -rw-r–r– 1 root root 84K Aug 18 09:38 uwsgi_help.txt -rw-r–r– 1 root root 389 Aug 17 17:54 uwsgi.ini (SIPEvents) ➜ SIPEvents export FLASK_APP=app.py (SIPEvents) ➜ SIPEvents export FLASK_DEBUG=1 (SIPEvents) ➜ SIPEvents uwsgi -s /tmp/uwsgi.sock –manage-script-name –mount /=app:hello –virtualenv /root/Envs/SIPEvents *** Starting uWSGI 2.0.13.1 (64bit) on [Thu Aug 18 16:26:12 2016] *** compiled with version: 4.4.7 20120313 (Red Hat 4.4.7-17) on 17 August 2016 17:19:10 os: Linux-3.10.101-1.el6.elrepo.x86_64 #1 SMP Wed Mar 16 20:55:27 EDT 2016 nodename: AY140128113754462e2eZ machine: x86_64 clock source: unix detected number of CPU cores: 2 current working directory: /usr/share/nginx/html/SIPEvents detected binary path: /root/Envs/SIPEvents/bin/uwsgi !!! no internal routing support, rebuild with pcre support !!! uWSGI running as root, you can use –uid/–gid/–chroot options *** WARNING: you are running uWSGI as root !!! (use the –uid flag) *** *** WARNING: you are running uWSGI without its master process manager *** your processes number limit is 31452 your memory page size is 4096 bytes detected max file descriptor number: 65535 lock engine: pthread robust mutexes thunder lock: disabled (you can enable it with –thunder-lock) uwsgi socket 0 bound to UNIX address /tmp/uwsgi.sock fd 3 Python version: 2.7.12 (default, Aug 15 2016, 11:09:04) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] Set PythonHome to /root/Envs/SIPEvents *** Python threads support is disabled. You can enable it with –enable-threads *** Python main interpreter initialized at 0x19f0d00 your server socket listen backlog is limited to 100 connections your mercy for graceful operations on workers is 60 seconds mapped 72768 bytes (71 KB) for 1 cores *** Operational MODE: single process *** mounting app:hello on / WSGI app 0 (mountpoint=’/’) ready in 0 seconds on interpreter 0x19f0d00 pid: 19609 (default app) *** uWSGI is running in multiple interpreter mode *** spawned uWSGI worker 1 (and the only) (pid: 19609, cores: 1) |
而之前的nginx的配置为:
去把
/etc/nginx/conf.d/default.conf
修改为:
➜ ~ cat /etc/nginx/conf.d/default.conf server { location / { try_files $uri @yourapplication; } location @yourapplication { include uwsgi_params; uwsgi_pass unix:/tmp/uwsgi.sock; } } |
然后去重启nginx:
(SIPEvents) ➜ SIPEvents service nginx restart Stopping nginx: [ OK ] Starting nginx: [ OK ] |
但是访问:
还是出现:
搜:
uWSGI Nginx 502 Bad Gateway
uWSGI Nginx Flask 502 Bad Gateway
NGINX+UWSGI 莫名发生Nginx 502 Bad Gateway错误的排查过程 – 猪在飞啊 – 博客园
flask uwsgi nginx 出现502 Bad Gateway – 前端开发&搜索引擎优化 – 博客频道 – CSDN.NET
使用uWSGI+Nginx部署Flask应用,不成功 – V2EX
python – UWSGI + NGINX 502 Bad Gateway – Stack Overflow
502 Bad Gateway error Nginx and uWSGI in deploying Flask app – Stack Overflow
放弃了。
算了。