gunicorn

在python的虚拟环境venv中使用gunicorn

匿名 (未验证) 提交于 2019-12-02 22:51:30
昨天遇到的问题,一个服务器上有好几个虚拟机环境。 我active进一个虚拟环境,安装了新的三方库之后, 使用gunicorn启动django服务, 但还是死活提示没有安装这个三方库。 一开始没有找到原因,后来,在启动的进程里发布了痕迹, 原来,这个gunicorn启动时的python为另一个venv里的python。 soga~~改过来罗。。。 /venv/bin/gunicorn #!/docker/venv/bin/python3.6 # -*- coding: utf-8 -*- import re import sys from gunicorn.app.wsgiapp import run if __name__ == '__main__': sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) sys.exit(run()) 注意红色部门的python要和自己的虚拟环境路径一致!!!!! 来源:博客园 作者: aguncn 链接:https://www.cnblogs.com/aguncn/p/11769431.html

Gunicorn启动flask项目

白昼怎懂夜的黑 提交于 2019-12-02 22:34:16
Gunicorn 是一个 unix 上被广泛使用的高性能的Python WSGI UNIX HTTP Server。 和大多数的web框架兼容,并具有实现简单,轻量级,高性能等特点 废话不多说,直接上干货!!!! 1.创建虚拟机--->自行百度,一大推 2.我这里用的centos7迷你版镜像,这个无所谓 3.干净的虚拟机无法使用wget,需要我们配置yum源!!!这个重点!!!!! yum国内仓库环境的搭建 yum源的仓库路径在/etc/yum.repos.d/然后这个目录底下,只有 以 .repo结尾的文件,才会被识别为yum仓库 1.在/etc/yum.repos.d/目录底下,定制我们自己的repo仓库文件 2.我们自己没有yum仓库,我们就去拿阿里巴巴的yum仓库 3.https://opsx.alibaba.com/mirror 这就是阿里巴巴的镜像站 4.下载阿里巴巴的yum仓库文件 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo wget下载文件后,-O参数,指定放到某个目录,且改名 5.清除yum缓存 yum clean all 6.生成新的阿里云的yum软件缓存 yum makecache View Code 4.yum源现在已经配置完成

Flask 系列之 部署发布

匿名 (未验证) 提交于 2019-12-02 22:11:45
操作系统:Windows 10 Python 版本:3.7x 虚拟环境管理器:virtualenv 代码编辑器:VS Code 通过 Windows 的 WSL ,将我们的项目网站部署到 Ubuntu 16.04 上面 打开 WSL,执行下述操作 安装 Python3 pip3 以及虚拟环境管理工具 virtualenv sudo apt-get install python3 sudo apt-get install python3-pip pip3 install virtualenv 安装并启动 Mysql 安装完成之后需要进入 Mysql 的 Shell 中创建我们程序需要实验的的数据库 todo 略,具体可参考: Flask 系列之 SQLAlchemy 安装并启动 Nginx # 安装并启动 Nginx sudo apt-get install nginx sudo service nginx start sudo service nginx stop 注:执行完毕后可尝试访问: http://127.0.0.1 , 看是否正常。 pip freeze > requirements.txt cp -R /mnt/c/Users/hippieZhou/Desktop/Flask_todolist /home/hippie/todolist cd /home/hippie

python+gunicorn+nginx部署遇到的坑

匿名 (未验证) 提交于 2019-12-02 22:10:10
gunicorn no module named flask 最近在Ubuntu上面部署Flask应用程序,报如下错误: File "/var/Material-Prices/app/__init__.py", line 2, in <module> ImportError: No module named flask 使用的是gunicorn,这个一看是缺少falsk模块,使用pip install flask,但是运行:gunicorn manage:manager 依然还是报相同错误。 产生原因: 由于某种原因,gunicorn将环境加载到虚拟环境之外。 我通过在虚拟环境之外卸载包gunicorn来解决问题。 解决方案: 首先退出虚拟环境,卸载gunicorn (env) $ deactivate $ sudo pip uninstall gunicorn 再次进入虚拟环境: $ source env/bin/activate (env) $ pip install gunicorn (env) $ gunicorn server:app 2018-6-13 [11923] [INFO] Listening at: http://127.0.0.1:8000 (11923) 文章来源: python+gunicorn+nginx部署遇到的坑

nginx+gunicorn项目部署

匿名 (未验证) 提交于 2019-12-02 21:53:52
mkdir data 目录文件夹 cd data 进入data文件夹 mkdir nginx 创建安装nginx的文件夹 mkdir server 存放代码的文件夹 mkdir logs 存放日志的文件夹 mkdir backup 备份代码的文件夹 mkdir softs 软件存放的位置 mkdir virtual 虚拟环境的位置 mkdir scripts 脚本的运行位置 mkdir scp_codes 上传的代码 apt-get install python-virtualenv (ubuntu已经安装过,可省略) virtualenv -p /usr/bin/python3 api_server (采用他,安装在本文件夹,) mkvirtualenv api_server(不要用它,它会自己安装到其他地方) source api_server/bin/activate (在虚拟环境的active进入虚拟环境) 安装的软件会在虚拟环境下的bin目录下 解压 cd ~/data/softs/ tar xf pcre-8.39.tar.gz 配置 cd ~/data/softs/pcre-8.39 ./configure 编译 make 安装 sudo make install 解压 cd ~/data/softs/ tar xf nginx-1.10.2.tar.gz 配置 cd

flask——接口简单示例

女生的网名这么多〃 提交于 2019-12-02 21:40:34
原文: https://www.cnblogs.com/liuzhen1995/p/8107905.html 目录 前言 1 准备工作 2 具体实现 前言 最近在捣鼓如何使用阿里云服务器搭建一个简单的基于Flask框架的后端接口,刚开始为了图方便,就直接买了一个Windows Server 2008系统服务器,这也埋下了不小的坑。 服务买下来后,会给你一个公网IP和内网IP,由于是第一次学习搭建后端接口,对于如何正确使用阿里云服务器,来处理好公网IP和内网IP之间的关系埋下了不小的坑,真是对应的一句话:技术的成长往往是一步一个坑。 下面简单说一下搭建Flask服务器端遇到的问题: 首先,Flask自带了一个服务器,直接使用很方便,不过这个服务器的性能太低,但是对于调试和学习还是绰绰有余。刚开始把代码放到阿里云服务器上,并跑通后,测试接口时公网IP无法访问,那时我以为是Flask自带服务器的问题,即因为Flask自带服务器原因导致无法使用公网IP访问。 那么,问题出现了,就要寻找解决办法吧,网上查找资料给出参照意见:使用nginx +gunicorn来部署Flask相关服务,可以避免公网IP无法访问问题。然后,我就去找资料,安装gunicorn,结果运行测试时一直报错,最后发现gunicorn不支持Windows系统,这也太坑了,早知道我当时买服务器时就不该图方便

在ubuntu13.10下使用gunicorn部署flask程序

南笙酒味 提交于 2019-12-02 21:15:25
其实我使用的linuxmint16 ,不过他是基于ubuntu13.10的,按照从网上找到的一片博文操作,基本ok,不过还是除了一些小问题,记录一下: 博文地址: How to Run Flask Applications with Nginx Using Gunicorn 我没用virtualenv 第一步:安装 gunicorn sudo pip install gunicorn #也可以 sudo easy_install gunicorn 第二步: 在 app.run() 的前面加上: from werkzeug.contrib.fixers import ProxyFix app.wsgi_app = ProxyFix(app.wsgi_app) 运行它: gunicorn hello:app 这个hello就是 app.run() 所在文件的名字,至于冒号后面的app自然就是app.run()的app了。 其实在文档里还有这样一种运行方法,不过我没成功: gunicorn -w 4 -b 127.0.0.1:4000 myproject:app 第三步,安装、配置nginx。 sudo apt-get install nginx sudo gedit /etc/nginx/sites-available/default server { listen 80;

使用Gunicorn部署 python应用程序

纵然是瞬间 提交于 2019-12-02 21:15:11
来源引用: https://www.digitalocean.com/community/tutorials/how-to-deploy-python-wsgi-apps-using-gunicorn-http-server-behind-nginx 关于 Gunicorn 和 Nginx ####Gunicorn Gunicorn is a stand-alone WSGI web application server which offers a lot of functionality. It natively supports various frameworks with its adapters, making it an extremely easy to use drop-in replacement for many development servers that are used during development. Technically, the way Gunicorn works is very similar to the successful Unicorn web server for Ruby applications. They both use what's referred to as the pre-fork model. This,

nginx unknown directive “upstream”

坚强是说给别人听的谎言 提交于 2019-12-02 20:36:37
I'm using nginx as a proxy server to forward requests onto my gunicorn server. When I run sudo nginx -t -c /etc/nginx/sites-enabled/mysite I get the following error. [emerg]: unknown directive "upstream" in /etc/nginx/sites-enabled/mysite:1 configuration file /etc/nginx/sites-enabled/mysite test failed Any idea how to fix it? This is my nginx config: upstream gunicorn_mysite { server 127.0.0.1:8000 fail_timeout=0; } server { listen 80; server_name example.com; access_log /usr/local/django/logs/nginx/mysite_access.log; error_log /usr/local/django/logs/nginx/mysite_error.log; location / { proxy

Fetching static files failed with 404 in nginx

浪尽此生 提交于 2019-12-02 20:21:48
I'm now deploying an django app with nginx and gunicorn on ubuntu 12. And I configure the nginx virtual host file as below: server { listen 80; server_name mydomain.com; access_log /var/log/nginx/gunicorn.log; location / { proxy_pass http://127.0.0.1:8000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /static/ { root /var/www/django/ecerp/erp/static/; } } I can request the django well, but when request a static file, it response with 404 status. I'm sure the root path of static file is correct. Can