Archlinux + nginx + flask 生产环境搭建

 

1. 安装python

$ sudo pacman -S python
$ mkdir ~/.pip
$ echo '[global]' > ~/.pip/pip.conf
$ echo 'index-url = https://pypi.tuna.tsinghua.edu.cn/simple' >> ~/.pip/pip.conf

2. 创建web目录

$ sudo mkdir -p /www/wwwroot/test/uwsgi

3. 创建test.py

$ sudo pip install flask
$ vim /www/wwwroot/test/test.py
====================================
from flask import Flask
 
 
app = Flask(__name__)
 
 
@app.route("/")
def index():
    return "Hello, World!"
 
 
if __name__ == '__main__':
    app.run(host='0.0.0.0')

4. 配置nginx

$ sudo pacman -S nginx
$ sudo systemctl enable nginx
$ sudo systemctl start nginx
$ sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf_backup
$ sudo vim /etc/nginx/nginx.conf
c============== 找到 location / { 段,改为 ====================c
        location / {
            include uwsgi_params;
            uwsgi_pass unix:/www/wwwroot/test/uwsgi/uwsgi.sock;
        }

$ sudo pip install uwsgi

5. 配置uwsgi

$ sudo pip install uwsgi
$ touch /www/wwwroot/test/uwsgi/{uwsgi.sock,uwsgi.status,uwsgi.pid,uwsgi.log}
$ vim /www/wwwroot/test/uwsgi.ini
========================================
[uwsgi]
chdir = /www/wwwroot/test
home = /www/wwwroot/test/.env
module = test
callable = app
master = true
processes = 2
# chmod-socket = 666
# logfile-chmod = 664
procname-prefix-spaced = test
py-autoreload = 1
# http = 0.0.0.0:8080
 
vacuum = true
socket = %(chdir)/uwsgi/uwsgi.sock
stats = %(chdir)/uwsgi/uwsgi.status
pidfile = %(chdir)/uwsgi/uwsgi.pid
daemonize = %(chdir)/uwsgi/uwsgi.log

6. 启动uwsgi

$ sudo chown http:http -R /www
$ sudo uwsgi --ini /www/wwwroot/test/uwsgi.ini

7. 参考

https://www.bilibili.com/video/BV1CJ411y7AW?from=search&seid=12835791166125293576

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值