温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么用flask+uwsgi+nginx把项目部署到服务器上

发布时间:2021-09-10 07:33:55 阅读:167 作者:chen 栏目:大数据
亿速云爆款云服务器,独享5M带宽,BGP线路,安全稳定,0.96元/天! 查看详情>>

本篇内容主要讲解“怎么用flask+uwsgi+nginx把项目部署到服务器上”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎么用flask+uwsgi+nginx把项目部署到服务器上”吧!

服务器部署一般是用nginx做负载均衡,用uwsgi转发到相应的web项目中去

安装 nginx(ubuntu和centos有区别)

sudo apt-get install nginx

安装uwsgi

pip3 install uwsgi

#将数据库迁移到服务器上

安装服务器

sudo apt-get install mysql-server (ubuntu版)

#打开数据库,创建一个数据库

create database_shop

导入本地创建的数据库文件

source (文件地址)

配置uwsgi.ini文件,这个文件跟uwsgi同行

[uwsgi]#使用nginx连接时使用,Django程序所在服务器地址;socket=127.0.0.1:8001#直接做web服务器使用,Django程序所在服务器地址http=0.0.0.0:8001#项目目录(manage.py所在目录)chdir=/home/ubuntu/apiwxcjsoft/apicjsoft#项目中wsgi.py文件的目录,相对于项目目录(写项目目录chdir之后的目录)wsgi-file=apicjsoft/wsgi.pycallable = app #flask_manager 需要加上这句话# 进程数processes=4# 线程数threads=2# uwsgi服务器的角色master=True# 存放进程编号的文件pidfile=uwsgi.pid# 日志文件,因为uwsgi可以脱离终端在后台运行,日志看不见我们以前的runserver是依赖终端的(会生成在与uwsgi.ini平级目录中)daemonize=uwsgi.log# 指定依赖的虚拟环境virtualenv=/home/ubuntu/apiwxcjsoft/apicjsoft/env

启动uwsgi命令

uwsgi --ini uwsgi.ini

关闭uwsgi命令

uwsgi --stop uwsgi.pid 关闭

配置nginx

ubuntu下找到/etc/nginx/sites-available下的default文件

server {        listen 80; #监听端口,一般为80#       listen [::]:80 default_server;        # SSL configuration        #        # listen 443 ssl default_server;        # listen [::]:443 ssl default_server;        #        # Note: You should disable gzip for SSL traffic.        # See: https://bugs.debian.org/773332        #        # Read up on ssl_ciphers to ensure a secure configuration.        # See: https://bugs.debian.org/765782        #        # Self signed certs generated by the ssl-cert package        # Don't use them in a production server!        #        # include snippets/snakeoil.conf;        root /var/www/html;        # Add index.php to the list if you are using PHP        index index.html index.htm index.nginx-debian.html;        server_name _;#配置转发地址,        location / {              include /etc/nginx/uwsgi_params;              uwsgi_pass 127.0.0.1:8001;#写在uwsgi.ini中得地址                # First attempt to serve request as file, then                # as directory, then fall back to displaying a 404.        #       try_files $uri $uri/ =404;        }

修改完后重新启动nginx

service nginx restart

停止命令

service nginx stop

启动命令

service nginx start

到此,相信大家对“怎么用flask+uwsgi+nginx把项目部署到服务器上”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

原文链接:https://my.oschina.net/u/3358983/blog/4349155

AI

开发者交流群×