在统信uos系统中部署openresty需按版本选择安装方式:uos server 1050a/e用yum,desktop/server 1050d用apt,离线环境须源码编译;版本确认命令为cat /etc/os-version或uname -a,包管理器不匹配将导致全部失败。

在统信UOS系统中快速部署具备Lua扩展能力的高性能Web服务,需根据具体版本选择匹配的安装路径——UOS Server 1050A/E用yum,UOS Desktop/Server 1050D用apt,离线环境则必须走源码编译。网络不通时强行用在线方法会卡在仓库更新环节,直接报错退出。
确认UOS版本类型
打开终端,执行:cat /etc/os-version 或 uname -a,重点看输出中是否含 【uos server 1050a】、【uos server 1050e】(对应yum系)或 【uos desktop 1050d】、【uos server 1050d】(对应apt系)。这一步跳过会导致后续所有命令失败,因为包管理器不兼容。
yum系系统安装OpenResty(UOS Server 1050A/E)
方法一:官方仓库一键安装
1. 安装仓库管理工具:sudo yum install -y yum-utils
2. 添加OpenResty官方CentOS兼容源:sudo yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo
3. 刷新并安装:sudo yum install -y openresty openresty-resty → 这步会自动拉取Nginx核心、LuaJIT及常用模块,无需单独装依赖
4. 启动并设为开机自启:sudo systemctl start openresty && sudo systemctl enable openresty
5. 验证:openresty -v,应输出类似 openresty/1.21.4.2 的版本号
apt系系统安装OpenResty(UOS Desktop/Server 1050D)
方法一:APT源安装(推荐)
第一步:导入GPG密钥防止包签名校验失败
执行:wget -O - https://openresty.org/package/pubkey.gpg | sudo apt-key add -
第二步:写入适配UOS的APT源地址echo "deb http://openresty.org/package/debian $(lsb_release -sc) openresty" | sudo tee /etc/apt/sources.list.d/openresty.list → 注意这里用的是 debian 路径而非 ubuntu,UOS 1050D底层基于Debian 12,硬套Ubuntu源会导致404
第三步:更新索引并安装sudo apt update && sudo apt install -y openresty
第四步:检查安装结果ls /usr/local/openresty/ 应看到 bin/ luajit/ nginx/ pod/ 等目录;openresty -V 显示完整编译参数
离线环境下源码编译安装
适用于无外网、等保三级及以上环境,或需启用PCRE-JIT、自定义模块的场景。整个过程必须在与目标机相同CPU架构(如arm64或amd64)的联网机器上完成预构建。
① 下载源码包(以最新稳定版为例):wget https://openresty.org/download/openresty-1.21.4.2.tar.gz
② 解压并进入目录:tar -zxf openresty-1.21.4.2.tar.gz && cd openresty-1.21.4.2
③ 安装构建依赖(在离线机上提前部署好这些rpm/deb包):
— yum系:sudo yum install -y gcc make pcre-devel openssl-devel zlib-devel readline-devel
— apt系:sudo apt install -y build-essential libpcre3-dev libssl-dev zlib1g-dev libreadline-dev
④ 配置编译选项(关键参数不可省):./configure \--prefix=/usr/local/openresty \--with-luajit \--with-http_ssl_module \--with-http_v2_module \--with-http_stub_status_module \--with-pcre-jit
⑤ 编译并安装:make -j$(nproc) && sudo make install → 编译耗时约8~15分钟,取决于CPU核心数
⑥ 配置环境变量(永久生效):echo 'export PATH=/usr/local/openresty/nginx/sbin:$PATH' >> ~/.bashrc && source ~/.bashrc
首次启动前的基础配置
编辑主配置文件:sudo nano /usr/local/openresty/nginx/conf/nginx.conf
定位到 http { ... } 块内,在末尾添加一个最简server块:
server { listen 80; server_name localhost; location / { default_type text/html; return 200 "OpenResty is running on UOS.\n"; }}
保存后执行语法检查:sudo nginx -t -c /usr/local/openresty/nginx/conf/nginx.conf → 若提示 success,说明配置无误
启动服务:sudo /usr/local/openresty/nginx/sbin/nginx
验证访问:curl http://127.0.0.1 → 返回 OpenResty is running on UOS.











