nginx+flask+uwsgi

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 { }

image.png

6:重启nginx服务:systemctl restart nginx
7:建立对应文件:
1)mkdir /myapp && cd /myapp
2) vim main.py
image.png

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```
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容