unit 对于nodejs 的支持是在10.25 发布的,基本能用,但是依然有好多问题,当前在测试的时候就发现,请求之后会block ,
相关的issue 已经有人反馈了,最好使用源码编译,方便测试,当前使用yum 的安装包会有点问题(block)

使用的操作系统是centos7

环境准备

  • 配置yum源
/etc/yum.repos.d/unit.repo
[unit]
name=unit repo
baseurl=https://packages.nginx.org/unit/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
  • 安装unit 以及需要的语言支持
yum install unit-php unit-python unit-go unit-perl unit-devel unit
  • 安装nodejs
yum install -y nodejs
升级node 版本
npm insatll -g n
n 8.11.4
  • 安装node-addon 构建依赖
yum install gcc-c++

基本项目

  • nodejs 项目结构(为了测试集成了php),目录/opt/nodejs
├── app.js
├── blogs
│ └── index.php
├── package.json
└── unit.json
  • 代码说明
package.json
{
"name": "nodejs",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"express": "^4.16.4",
"unit-http": "^1.5.1"
}
}
app.js: 使用unit 的http 模块托管管理http server
#!/usr/bin/env node
const {
createServer,
IncomingMessage,
ServerResponse,
} = require('unit-http') require('http').ServerResponse = ServerResponse
require('http').IncomingMessage = IncomingMessage const express = require('express') const app = express() app.get('/', (req, res) => {
res.set('X-Unit-Type', 'Absolute')
res.send('Hello, Unit!')
}) createServer(app).listen()
index.php
<?php
echo "php demo website"
?>
unit.json unit 服务配置文件
{
"listeners": {
"*:8080": {
"application": "hello-unit"
},
"*:8300": {
"application": "blogs"
}
},
"applications": {
"hello-unit": {
"type": "external",
"working_directory": "/opt/nodejs",
"executable": "app.js",
"processes":5
},
"blogs": {
"type": "php",
"processes": 5,
"root": "/opt/nodejs/blogs",
"index": "index.php"
}
}
}

服务启动&&测试

  • 启动服务(使用systemd 管理修改了启动controller 访问地址)
cat /etc/sysconfig/unit
UNITD_OPTIONS="--log /var/log/unit.log --pid /run/unit.pid --control 0.0.0.0:9000"
systemctl restart unit
  • 注册服务
curl -X PUT -d @$PWD/start.json http://localhost:9000/config
  • 查看结果


说明

现在的版本已经挺不错了,支持状态管理,默认在/var/lib/unit/conf.json,重启之后服务可以自动注册。
目前测试nodejs 模块是有点问题的,请求之后会block https://github.com/nginx/unit/issues/175
格式如下:

{"listeners":{"*:8080":{"application":"hello-unit"},"*:8300":{"application":"blogs"}},"applications":{"hello-unit":{"type":"external","working_directory":"/opt/nodejs","executable":"app.js","processes":5},"blogs":{"type":"php","processes":5,"root":"/opt/nodejs/blogs","index":"index.php"}}}

参考资料

https://github.com/nginx/unit/issues/175
https://unit.nginx.org/installation/#node-js-package
https://unit.nginx.org/configuration/
https://medium.com/house-organ/what-an-absolute-unit-a36851e72554

 
 
 
 

nginx unit nodejs 模块试用的更多相关文章

  1. nginx unit nodejs 模块试用(续)

      最新(应该是18 年了)nginx unit 发布了新的版本,对于nodejs 的支持有很大的改进,上次测试过,问题还是 比较多,这次使用新版本在测试下对于nodejs 的支持,以及以前block ...

  2. nginx unit java 试用

    unit 当前已经支持java了,当时支持基于servlet 的开发模式,以下是一个简单的学习 基于官方的demo 环境准备 docker-compose文件   version: "3&q ...

  3. 为nginx增加nginx_http_concat模块

    为nginx增加nginx_http_concat模块 时间 2013-06-05 22:14:56  我行我思 原文  http://www.fanjun.me/?p=562 主题 Nginx 缘由 ...

  4. nginx Unit 服务器

    转自: https://github.com/nginx/unit/pull/18/ 感谢: https://www.v2ex.com/t/389528 English 简体中文 繁體中文 NGINX ...

  5. NodeJS 模块开发及发布详解

    NodeJS 是一门年轻的语言,扩展模块并不太全,经常我们想用某个模块但是却找不到合适的.比如前两天我需要使用hmac和sha1来做签名,就没有找到一个比较好用的模块,这时候就需要我们自己来实现相应的 ...

  6. nginx利用geo模块做限速白名单以及geo实现全局负载均衡的操作记录

    geo指令使用ngx_http_geo_module模块提供的.默认情况下,nginx有加载这个模块,除非人为的 --without-http_geo_module.ngx_http_geo_modu ...

  7. Nginx做NodeJS应用负载均衡配置实例

    这篇文章主要介绍了Nginx做NodeJS应用负载均衡配置实例,本文直接给出配置实例,需要的朋友可以参考下. 负载均衡可以把用户的请求分摊到多个服务器上进行处理,从而实现了对海量用户的访问支持.负载均 ...

  8. php5.5安装及phpmyadmin&nginx配置php模块

    安装php5.5: 下载源地址:rpm -Uvh rpm包安装:yum install php55w.x86_64 php55w-cli.x86_64 php55w-common.x86_64 php ...

  9. Nginx SPDY Pagespeed模块编译——加速网站载入

    在看<Web性能权威指南>的时候,看到了SPDY这货,于是便开始折腾起了这个了,也顺便把pagespeed加了进去. Nginx SPDY 引自百科~~ SPDY(读作“SPeeDY”)是 ...

随机推荐

  1. Mac安装软件时 提示已损坏的解决方法

    进入终端: sudo spctl --master-disable

  2. android--------验证码倒计时

    在我们注册或者修改信息的时候,常会用到60s倒计时这个功能,写了这篇文章,大家共享一下: 效果图: 直接上代码: activity.java public class MainActivity ext ...

  3. python-day67--MTV之Template

    一.什么是模板? html+模板语法 二.模版包括在使用时会被值替换掉的 变量,和控制模版逻辑的 标签. 三.嵌入变量的三种方式: def current_time(req): # ========= ...

  4. HDU-4471 Yet Another Multiple Problem (BFS+路径还原)

    Problem Description There are tons of problems about integer multiples. Despite the fact that the to ...

  5. 一篇来自网络的关于“enqueue”events的简短参考(转)

    仅供自己和各位同学参考: Enqueue Type Description enq: AD - allocate AU Synchronizes accesses to a specific OSM ...

  6. swiper中的默认值的属性和作用(小程序交流群:604788754)

    swiper中的重要属性: vertical:属性,控制swiper效果是水平切换滚动,还是垂直切换滚动.如果不设置此属性,默认是水平滚动,如果设置:vertical="true" ...

  7. Maven 入门篇(下)

    第一篇文章大概的介绍了一下Apache Maven以及它的下载和安装,并且运行了一个简单的示例.那么在对maven有了一点接触后,接下去的一步是要了解maven的核心概念,这样才能在使用maven的时 ...

  8. HDU 4635 Strongly connected (Tarjan+一点数学分析)

    Strongly connected Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) ...

  9. Java——线程池

    body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...

  10. python面试知识总结

    1. 先做自我介绍 2. 做Python几年了?为什么选择Python?3. 学历?大学什么专业?4. 除了Python以外对其他语言有没有了解?5. 你对Python这门语言的看法?6. 在学习Py ...