前一段时间我发了个贴: http://v2ex.com/t/254525
经过几天的努力,终于把搭建 Flask 遇到的大多数坑都踩了一遍,现在把它做成一个一键脚本,发给大家供大家使用。
默认使用的是 80 端口,可以通过修改 hosts 文件,将 default.site 解析成当前服务器的 IP 地址,否则会打开 Fedora 内置的 nginx 默认界面。
由于 nginx 与 uwsgi 之间使用 socket 通讯,而 Fedora23 默认是开启 SELINUX 的,会造成网页打不开弹 502 ,而要禁用 SELINUX 的话就必须重启,所以脚本最后加了个 reboot 。
接下来放脚本,欢迎反馈 BUG ,或者交金币 (^-^)
#!/bin/bash
echo
echo "#####################################################"
echo "# #"
echo "# update system and install some software #"
echo "# #"
echo "#####################################################"
echo
dnf install nginx uwsgi uwsgi-plugin-python3 mariadb-server python3-pip vim git -y
pip3 install --upgrade pip
pip3 install virtualenv
systemctl enable nginx
systemctl enable uwsgi
systemctl enable mariadb
firewall-cmd --add-service=http --permanent
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
echo
echo "#####################################################"
echo "# #"
echo "# install flask environment #"
echo "# #"
echo "#####################################################"
echo
mkdir -p /var/web/default.site
cd /var/web/default.site
virtualenv venv
source venv/bin/activate
pip3 install flask
deactivate
echo
echo "#####################################################"
echo "# #"
echo "# edit some config files #"
echo "# #"
echo "#####################################################"
echo
cat > /etc/nginx/conf.d/default.site.conf << EOF
server
{
listen 80;
server_name default.site;
root /var/web/default.site;
location /
{
include uwsgi_params;
uwsgi_pass 127.0.0.1:8000;
}
}
EOF
cat > /etc/uwsgi.d/default.site.ini << EOF
[uwsgi]
socket = :8000
processes = 2
chdir = /var/web/default.site
home = /var/web/default.site/venv
wsgi-file = /var/web/default.site/manager.py
callable = app
plugins = python3
master = true
vacuum = true
EOF
chown uwsgi:uwsgi /etc/uwsgi.d/*
cat > /var/web/default.site/manager.py << EOF
#!/usr/bin/env python3
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return "<span style='color:red'>Flask is running...</span>\n"
EOF
reboot
1
fyyz OP 一楼自己占了,收金币
|
2
wolfan 2016-02-01 21:46:43 +08:00 via Android
送铜币
|
3
rootit 2016-02-02 09:07:34 +08:00
setenforce 0 即时生效 disabele selinux
|
4
rim99 2016-02-02 10:00:16 +08:00
挺好 收了
|