美文网首页
ubuntu服务器用apache2部署flask

ubuntu服务器用apache2部署flask

作者: 放开那个电扇 | 来源:发表于2018-05-06 00:28 被阅读0次

ssh登录服务器
先把服务器的ip地址添加进hosts文件
vi /etc/hosts
添加一行
127.0.0.1 localhost
127.0.1.1 ubuntu
127.0.0.1 localhost.example localhost

The following lines are desirable for IPv6 capable hosts

xxx.xxx.xxx.xxx localhost.example localhost
xxx为服务器ip地址

安装wsgi
安装apache2

在flask目录下新建.wsgi文件,例如app.wsgi
vi app.wsgi
输入内容
import sys
sys.path.insert(0, "/var/www/qwer")
from qwer1 import app as application
app.wsgi完整路径为 /var/www/qwer/app.wsgi 很重要

在Apache2配置文件目录新建一个配置,例如qwer.conf
vi /etc/apache2/sites-available/qwer.conf
输入内容
<VirtualHost *:80>
ServerName xxx.xxx.xxx.xxx
ServerAlias xxx.xxx.xxx.xxx
WSGIDaemonProcess qwer threads=5
WSGIScriptAlias / /var/www/qwer/app.wsgi
<Directory /var/www/qwer>
WSGIProcessGroup qwer
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On
Order deny,allow
Allow from all
</Directory>
</VirtualHost>

使刚配置的站点文件生效 a2ensite qwer.conf

重新加载apache配置文件 service apache2 reload

打开xxx.xxx.xxx.xxx可以看到运行的flask程序

如果打开网页发现apache服务器500错误,可以使用apachectl -t查看错误信息
然后使用tail -100 /var/log/apache2/error.log 查看Apache2错误日志来排查错误

flask默认使用python2 后安装的python3待验证

相关文章

网友评论

      本文标题:ubuntu服务器用apache2部署flask

      本文链接:https://www.haomeiwen.com/subject/pfdyrftx.html