最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]已安装Flask的虚拟环境中无法正常运行uwsgi

Flask crifan 4484浏览 0评论

折腾:

[已解决]CentOS中如何将http对于Nginx的请求转到Flask服务器中

去搜:

centos redirect nginx to flask

How To Deploy Flask Web Applications Using uWSGI Behind Nginx on CentOS 6.4 | DigitalOcean

在 CentOS 上使用 Nginx/uWSGI 部署 Flask 网站应用 – 编程语言 / Python – CoCode

阿里云部署 Flask + WSGI + Nginx 详解-nginx-爱好Linux技术网

centos 6.4下nginx+uwsgi+flask的运行环境搭建详细记录 – 快乐编程

Flask:在Centos上配置两个Flask项目 | 酸菜鱼

去安装uwsgi

(SIPEvents)  SIPEvents pip install uwsgi
Collecting uwsgi
  Downloading uwsgi-2.0.13.1.tar.gz (784kB)
    100% || 788kB 62kB/s 
Building wheels for collected packages: uwsgi
  Running setup.py bdist_wheel for uwsgi … done
  Stored in directory: /root/.cache/pip/wheels/01/e4/de/0b2bbeba234858bd780924d03031a4e817119aafb0cfc4c79e
Successfully built uwsgi
Installing collected packages: uwsgi
Successfully installed uwsgi-2.0.13.1

uwsgi 配置

uwsgi 配置 flask

Django Nginx+uwsgi 安装配置 | 菜鸟教程

使用uwsgi和Nginx部署flask应用 – lncwwn – SegmentFault

uWSGI — Flask 0.10.1 文档

在 Ubuntu 上使用 Nginx 部署 Flask 应用 – 技术翻译 – 开源中国社区

Python/WSGI 应用快速入门 — uWSGI 2.0 文档

然后去配置uwsgi:

(SIPEvents)  nginx cd conf.d 
(SIPEvents)  conf.d ll
total 12K
-rw-r–r– 1 root root 1.3K Jun 17  2015 default.conf
-rw-r–r– 1 root root  466 Jun 17  2015 ssl.conf
-rw-r–r– 1 root root  283 Jun 17  2015 virtual.conf
(SIPEvents)  conf.d vspevents.conf                   
(SIPEvents)  conf.d vi sipevents.conf
location / {
    include uwsgi_params;
    uwsgi_pass 127.0.0.1:8080;
}
(SIPEvents)  conf.d nginx -t -c /etc/nginx/conf.d/sipevents.conf 
nginx: [emerg] unknown directive "location" in /etc/nginx/conf.d/sipevents.conf:1
nginx: configuration file /etc/nginx/conf.d/sipevents.conf test failed
(SIPEvents)  conf.d cat sipevents.conf 
server {
        listen 80;
        server_name 127.0.0.1:8080;
        location / {
        include uwsgi_params;
                uwsgi_pass unix:/tmp/uwsgi.sock;
        }
}
(SIPEvents)  conf.d ngnginx -t -c /etc/nginx/conf.d/sipevents.conf 
nginx: [emerg] unknown directive "server" in /etc/nginx/conf.d/sipevents.conf:1
nginx: configuration file /etc/nginx/conf.d/sipevents.conf test failed

flask 配置 uwsgi nginx

腾讯云配置:Flask+uWSGI+Nginx – Lingfeng’s Blog

UWSGI + Nginx 部署 Flask web 应用 – Daniel 的技术笔记 不积跬步无以至千里,不积小流无以成江海。 – 博客频道 – CSDN.NET

在Ubuntu通过Nginx和uwsgi部署Flask – – ITeye技术网站

uWSGI — Flask Documentation (0.11)

独立 WSGI 容器 — Flask 0.10.1 文档

Serving Flask with Nginx – Vladikk

使用nginx + uWSGI运行flask程序 – 老高的技术博客

用代码:

(SIPEvents)  SIPEvents cat app.py 
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
    return "Hello World!"
if __name__ == "__main__":
    app.run(host=’0.0.0.0′, port=8080)

运行出错:

(SIPEvents)  SIPEvents uwsgi -s /tmp/uwsgi.sock –chmod-sock=666 -H /usr/share/nginx/html/SIPEvents –module app –callable hello
*** Starting uWSGI 2.0.13.1 (64bit) on [Wed Aug 17 20:38:11 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 /usr/share/nginx/html/SIPEvents
ImportError: No module named site

搜:

uwsgi ImportError: No module named site

python – Flask+Nginx+uWSGI : ImportError: No module named site – Stack Overflow

试了几种:

uwsgi -s /tmp/uwsgi.sock –chmod-sock=666 -H /usr/share/nginx/html/SIPEvents –module app –callable hello
uwsgi -s /tmp/uwsgi.sock –chmod-sock=666 -H /usr/share/nginx/html/SIPEvents –module app –callable app
uwsgi -s /tmp/uwsgi.sock –chmod-sock=666 -H /root/Envs –module app –callable app
uwsgi –http-socket 127.0.0.1:8080 –wsgi-file /usr/share/nginx/html/SIPEvents/app.py –callable hello -H /root/Envs

问题依旧。

uWSGI + virtualenv ‘No module named site’ – Stack Overflow

django – Nginx & uWSGI: ImportError: No module named site – Server Fault

linux – Uwsgi configuration – No module called site – Server Fault

uwsgi + Flask + virtualenv ImportError: no module named site-open source projects unbit/uwsgi

加上–no-site好像就可以了:

(SIPEvents)  SIPEvents uwsgi -s /tmp/uwsgi.sock –chmod-sock=666 -H /root/Envs –module app –callable app –no-site
*** Starting uWSGI 2.0.13.1 (64bit) on [Wed Aug 17 20:56:11 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
*** Python threads support is disabled. You can enable it with –enable-threads ***
Python main interpreter initialized at 0x270fd60
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 ***
Traceback (most recent call last):
  File "./app.py", line 1, in <module>
    from flask import Flask
ImportError: No module named flask
unable to load app 0 (mountpoint=”) (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 9379, cores: 1)

但是又出现:

uwsgi ImportError: No module named flask

python – No module named flask while running uWSGI – Stack Overflow

Nginx+uwsgi+Flask部署 – 奋斗 – 博客频道 – CSDN.NET

试试:

uwsgi -s /tmp/uwsgi.sock –chmod-sock=666 -H /root/Envs –module app –callable app –no-site –plugin python2

问题依旧。

不过这时候,访问:

http://115.29.173.126/

出现:

Internal Server Error

然后此时命令行中也输出:

<div–<- no python application found, check your startup logs for errors —
[pid: 9534|app: -1|req: -1/1] 106.187.92.207 () {40 vars in 702 bytes} [Wed Aug 17 21:04:38 2016] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)

<div–<- no python application found, check your startup logs for errors —

[pid: 9534|app: -1|req: -1/2] 106.187.92.207 () {40 vars in 702 bytes} [Wed Aug 17 21:04:39 2016] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)

<div–<- no python application found, check your startup logs for errors —

[pid: 9534|app: -1|req: -1/3] 106.187.92.207 () {40 vars in 702 bytes} [Wed Aug 17 21:04:40 2016] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)

虽然出错,但是至少有动静了。

"ImportError: No module named flask" – Trouble with nginx + uWSGI + Flask in a virtualenv setup – Server Fault

用:

uwsgi -s /tmp/uwsgi.sock –chmod-sock=666 -H /root/Envs –callable app –no-site –wsgi-file app.py –pythonpath /root/Envs/SIPEvents/lib/python2.7/site-packages

输出:

added /root/Envs/SIPEvents/lib/python2.7/site-packages/ to pythonpath.
added /usr/share/nginx/html/SIPEvents/ to pythonpath.
Traceback (most recent call last):
  File "app.py", line 1, in <module>
    from flask import Flask
  File "/root/Envs/SIPEvents/lib/python2.7/site-packages/flask/__init__.py", line 17, in <module>
    from werkzeug.exceptions import abort
  File "/root/Envs/SIPEvents/lib/python2.7/site-packages/werkzeug/__init__.py", line 17, in <module>
    from types import ModuleType
ImportError: No module named types
unable to load app 0 (mountpoint=”) (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 9679, cores: 1)

nginx – Specifying virtualenv correctly in uwsgi.conf – Unix & Linux Stack Exchange

Python/WSGI 应用快速入门 — uWSGI 2.0 文档

uWSGI — Flask 0.10.1 文档

(SIPEvents)  SIPEvents deactivate
 SIPEvents pip install uwsgi
Collecting uwsgi
Installing collected packages: uwsgi
Successfully installed uwsgi-2.0.13.1
 SIPEvents

结果还是类似错误:

 SIPEvents uwsgi -s /tmp/uwsgi.sock –chmod-sock=666 –module app –callable hello
*** Starting uWSGI 2.0.13.1 (64bit) on [Wed Aug 17 21:24:35 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: /usr/local/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)]
*** Python threads support is disabled. You can enable it with –enable-threads ***
Python main interpreter initialized at 0x130ec30
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 ***
Traceback (most recent call last):
  File "./app.py", line 1, in <module>
    from flask import Flask
ImportError: No module named flask
unable to load app 0 (mountpoint=”) (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 9797, cores: 1)

[整理]uwsgi作用和语法

然后就可以继续去:

[记录]尝试去在CentOS中折腾uwsgi

转载请注明:在路上 » [已解决]已安装Flask的虚拟环境中无法正常运行uwsgi

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.186 seconds, using 22.13MB memory