You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在无pip且无对应配方的Yocto环境中安装uWSGI

Yocto环境下安装配置uWSGI的可行方案

针对你使用的Poky 2.2(Jethro)、Python2.7.12环境,以下是无需pip、手动适配Yocto的uWSGI安装配置步骤:

一、编写uWSGI的Yocto配方(核心步骤)

因为没有现成配方,直接在自定义layer里创建recipes-devtools/uwsgi/uwsgi_2.0.19.bb(2.0.19是和Python2.7兼容的稳定版本,可按需替换),内容如下:

SUMMARY = "Fast, self-healing application container server"
HOMEPAGE = "https://uwsgi-docs.readthedocs.io/"
LICENSE = "GPL-2.0"
LIC_FILES_CHKSUM = "file://COPYING;md5=eb723b61539feef013de476e68b5c50a"

# 替换成对应版本的下载链接和校验值,可从uWSGI官网获取
SRC_URI = "https://projects.unbit.it/downloads/uwsgi-${PV}.tar.gz"
SRC_URI[md5sum] = "d41d8cd98f00b204e9800998ecf8427e"

DEPENDS = "python2"
inherit pythonnative

do_compile() {
    # 针对Python2.7编译uWSGI
    ${PYTHON} uwsgiconfig.py --build python27
}

do_install() {
    # 安装uWSGI二进制到目标系统
    install -d ${D}${bindir}
    install -m 0755 uwsgi ${D}${bindir}/

    # 安装Python装饰器模块
    install -d ${D}${PYTHON_SITEPACKAGES_DIR}
    install -m 0644 uwsgidecorators.py ${D}${PYTHON_SITEPACKAGES_DIR}/
}

FILES_${PN} = "${bindir}/uwsgi ${PYTHON_SITEPACKAGES_DIR}/uwsgidecorators.py"

写完后,把这个配方所在的layer添加到bblayers.conf,重新构建镜像即可将uWSGI打包进去。

二、uWSGI与Flask、Nginx的集成配置

1. 配置uWSGI启动参数

在目标系统中创建/etc/uwsgi/flask_app.ini,根据你的Flask应用路径调整:

[uwsgi]
# 和Nginx通信的Unix套接字
socket = /tmp/flask_app.sock
# 给套接字设置权限,让Nginx能访问
chmod-socket = 666
# Flask应用入口:假设你的代码文件是app.py,里面的Flask实例叫app
module = app:app
# 进程和线程数,根据硬件配置调整
processes = 4
threads = 2
# 后台运行并输出日志
daemonize = /var/log/uwsgi/flask_app.log
# Flask代码所在目录
chdir = /opt/flask_app

2. 调整Nginx配置

在已有的Nginx server块中添加反向代理规则,指向uWSGI套接字:

server {
    listen 80;
    server_name your_server_ip;

    # 代理Flask请求到uWSGI
    location / {
        include uwsgi_params;
        uwsgi_pass unix:/tmp/flask_app.sock;
    }

    # 保留你已有的React静态文件配置
    location /static {
        root /opt/react_app/build;
        expires 30d;
    }
}

3. 添加systemd启动服务

创建/lib/systemd/system/uwsgi-flask.service,让uWSGI随系统启动:

[Unit]
Description=uWSGI service for Flask application
After=network.target

[Service]
User=root
Group=root
WorkingDirectory=/opt/flask_app
ExecStart=/usr/bin/uwsgi --ini /etc/uwsgi/flask_app.ini

[Install]
WantedBy=multi-user.target

执行以下命令启用并启动服务:

systemctl enable uwsgi-flask.service
systemctl start uwsgi-flask.service

三、验证运行

  • 查看uWSGI日志:cat /var/log/uwsgi/flask_app.log,确认无启动错误
  • 重启Nginx:systemctl restart nginx
  • 访问服务器IP,检查React页面和Flask接口是否都能正常响应

内容的提问来源于stack exchange,提问作者Robin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 21:35:37