flask+uwsgi+nginx+cerbot配置

配置步骤

安装flask和uwsgi

pip install Flask uwsgi

创建一个简单的flask应用(app.py)或者是自己的flask项目

from flask import Flask
app = Flask(__name__)
 
@app.route('/')
def hello_world():
    return 'Hello, World!'

配置uwsgi,这里我给出自己的配置

[uwsgi]
socket = :5000
wsgi-file = /root/blog/start.py
master = true
callable = app
chdir = /root/blog/
module = start:app
harakiri = 30
vacuum = true
die-on-term = true
limit-as = 512
buffer-size=65535
  • socket应该是和nginx通信的socket,注意不是http,因为uwsgi和nginx通信使用的是uwsgi协议
  • wsgi-file是程序启动文件,也就是python xxx.py的那个文件,注意写绝对路径
  • calllable是程序启动文件中应用的名字,一般就是app(xxx.run()那个xxx)
  • chdir是项目的根目录,建议写绝对路径
  • module的start是程序启动文件不带.py,app就是上面callable那个app
  • 其余参数不用修改

启动uwsgi

uwsgi --ini uwsgi.ini

 配置Nginx (/etc/nginx/sites-available/default)

server {
    listen 80;
    server_name your_domain.com;
 
    location / {
        include uwsgi_params;
        uwsgi_pass the_uwsgi_socket:port;
    }
}

需要修改的是your_domain.com是域名,the_uwsgi_socket就写0.0.0.0,port和uwsgi配置中socket端口保持一致,我这里就是5000

启动nginx

sudo systemctl start nginx

安装Cerbot

sudo apt-get install certbot python3-certbot-nginx

使用certbot为nginx配置https

sudo certbot --nginx

问题及解决

  • The -s/--socket option is missing and stdin is not a socket. 

https://www.cnblogs.com/qiaoer1993/p/16282109.html

  • unable to load configuration from uwsgi

https://stackoverflow.com/questions/34615743/unable-to-load-configuration-from-uwsgi

参考

How To Serve Flask Applications with uWSGI and Nginx on Ubuntu 22.04 | DigitalOcean

我的博客

不负长风

相关推荐

  1. Git<span style='color:red;'>配置</span>

    Git配置

    2024-04-28 07:30:05      64 阅读
  2. Redisson配置

    2024-04-28 07:30:05       60 阅读
  3. nginx配置

    2024-04-28 07:30:05       62 阅读
  4. VLAN配置

    2024-04-28 07:30:05       55 阅读
  5. XMLParser配置

    2024-04-28 07:30:05       57 阅读
  6. Redis 配置

    2024-04-28 07:30:05       49 阅读
  7. NAT<span style='color:red;'>配置</span>

    NAT配置

    2024-04-28 07:30:05      62 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-28 07:30:05       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-28 07:30:05       106 阅读
  3. 在Django里面运行非项目文件

    2024-04-28 07:30:05       87 阅读
  4. Python语言-面向对象

    2024-04-28 07:30:05       96 阅读

热门阅读

  1. 01-DispatchServlet和RequestMapping

    2024-04-28 07:30:05       26 阅读
  2. 14-@Autowired处理

    2024-04-28 07:30:05       29 阅读
  3. 数据结构––串

    2024-04-28 07:30:05       30 阅读
  4. 嵌入式学习63-C++

    2024-04-28 07:30:05       33 阅读
  5. IP模块——计算机网络

    2024-04-28 07:30:05       32 阅读
  6. test-demo-record

    2024-04-28 07:30:05       32 阅读
  7. partition global index 大全 UPDATE GLOBAL INDEXES

    2024-04-28 07:30:05       80 阅读
  8. 介绍 TensorFlow 的基本概念和使用场景

    2024-04-28 07:30:05       181 阅读
  9. 五个衰落的编程语言

    2024-04-28 07:30:05       32 阅读
  10. Python基础12-爬虫抓取网页内容

    2024-04-28 07:30:05       66 阅读