阿里云服务器 debian9 apache2 部署flask+wsgi 过程总结
由于阿里云镜像自带的源更新比较缓慢,最新的python3版本还是3.5,而我的代码使用的库需要python3.6+,因此需要先更新debian源:
vim /etc/apt/sources.list
在其中添加:
deb http://mirrors.163.com/debian/ testing main
执行:
apt-get update apt-get install python3.6 python3.6-dev python3.6-distutils apt-get install python-pip
安装wsgi:
sudo apt-get install libapache2-mod-wsgi-py3
在/etc/apache2/sites-available中新建flask.conf文件,在其中输入:
WSGIPythonPath /var/www/html/flask <VirtualHost *:80> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. ServerName flask.yunwei123.tech # ServerAdmin webmaster@localhost DocumentRoot /var/www/html/flask # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, e.g. #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined WSGIScriptAlias / /var/www/html/flask/app.wsgi <Directory /var/www/html/flask> Require all granted <Files app.wsgi> Allow from all </Files> </Directory> # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf </VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
保存。
在网站根目录(这里是)新建app.wsgi文件,输入:
from server import app as application
再在同一个目录下新建server.py, 输入:
from flask import Flask import platform print(platform.python_version()) app = Flask(__name__) @app.route('/') def hello_world(): return platform.python_version() if __name__ == '__main__': app.run(host='0.0.0.0')
打开网页就可以看到啦。
这里搭建的网页:
使用 flask + pyechart 搭建的简单新冠肺炎疫情数据可视化交互分析平台,包含疫情数据获取、态势感知、预测分析、舆情监测等任务:http://flask.yunwei123.tech/进行查看
包含完整代码和实现的github地址:
https://github.com/yunwei37/COVID-19-NLP-vis

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
架构师应该具备哪些思维模型?
架构师一直是程序员「羡慕且追求」的高度,今天来说说我(奈学教育CEO:孙玄)眼里优秀的架构师该如何定义。毕竟我也曾经是一名架构师: 在开始今天的话题之前我说一个和我前公司P9现在已经是P10的对话。 问题是这样的他说公司中间件架构师不熟悉公司业务,很多事落地不了,非常的疑惑。他最近主要任务就是和这些架构师聊天解惑:) 接着他说了一个类比的故事大概是这样的, 我们(架构师)要建设一条高速公路,来分别看看公路建造者(架构师)和司机(业务研发)的视角。 1,建造者 他们选用最好的沙子 水泥 更好的设计图纸和操作流程保证质量和处理异常情况(比如出入口提示,超车,紧急停车带) 2,司机同志 他们关心什么? 司机关心路宽么,有堵车可以提前告知么。 司机关心路平整么?当然关心,关心。 引出一个的问题:司机(业务研发)关心用最好的水泥么 ? 想象你是司机(业务研发)你你关心吗? A,关心 B,不关心 欢迎留言留下你的思考。 我觉得一名优秀的架构师,在设计系统时需要有以下这四项关键能力:「平衡取舍、预判未来、抽象思维、容错机制」。 平衡取舍 一个架构本质上总会有优有劣,它不可能是完美的、普适的,也不存在...
- 下一篇
如何在 Ubuntu 20.04 上安装 GCC(build-essential)
本文最先发布在:https://www.itcoder.tech/posts/how-to-install-gcc-on-ubuntu-20-04/ GNU 编译器集合是一系列用于语言开发的编译器和库的集合,包括: C, C++, Objective-C, Fortran, Ada, Go, and D等编程语言。很多开源项目,包括 Linux kernel 和 GNU 工具,都是使用 GCC 进行编译的。 本文描述如何在 Ubuntu 20.04 上安装 GCC。 一、在 Ubuntu 20.04 上安装 GCC 默认的 Ubuntu 软件源包含了一个软件包组,名称为 "build-essential",它包含了 GNU 编辑器集合,GNU 调试器,和其他编译软件所必需的开发库和工具。 想要安装开发工具软件包,以 拥有 sudo 权限用户身份或者 root 身份运行下面的命令: sudo apt update sudo apt install build-essential 这个命令将会安装一系列软件包,包括gcc,g++,和make。 你可能还想安装关于如何使用 GNU/Linux...
相关文章
文章评论
共有0条评论来说两句吧...