1:准备环境:
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
2:安装python
1)下载包:wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz
2)解压:tar -xvJf Python-3.6.4.tar.xz
3)切换目录:cd Python-3.6.4/
4)编译安装:./configure prefix=/usr/local/python3
make && make install
5)建立软链接:ln -s /usr/local/python3/bin/python3 /usr/bin/python3 && ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
3:安装uwigi:pip3 install uwsgi
4:nginx安装:yum install nginx -y
5:修改ngix配置:vim /etc/nginx/nginx.conf server { listen 80 default_server; listen [::]:80 default_server; server_name localhost; root /myapp; location /myapp { include uwsgi_params; uwsgi_param SCRIPT_NAME /myapp; uwsgi_pass unix:/tmp/uwsgi.sock; } error_page 404 /404.html; location = /404.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { }
6:重启nginx服务:
systemctl restart nginx
7:建立对应文件:
1)
mkdir /myapp && cd /myapp
2)
vim main.py
app = Flask(__name__)
@app.route("/")
def hello():
return "<h1 style="color:blue">Hello There!</h1>"
if __name__ == "__main__":
app.run(host='0.0.0.0')```
4)```vim run.py```
![image.png](https://upload-images.jianshu.io/upload_images/20498768-df46b1321e38fc95.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
```from main import app
if __name__ == "__main__":
app.run()```
8:启动服务uwsgi --socket 0.0.0.0:80 --protocol=http -p 3 -w run:app```