nginx unit nodejs 模块试用
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 模块试用的更多相关文章
- nginx unit nodejs 模块试用(续)
最新(应该是18 年了)nginx unit 发布了新的版本,对于nodejs 的支持有很大的改进,上次测试过,问题还是 比较多,这次使用新版本在测试下对于nodejs 的支持,以及以前block ...
- nginx unit java 试用
unit 当前已经支持java了,当时支持基于servlet 的开发模式,以下是一个简单的学习 基于官方的demo 环境准备 docker-compose文件 version: "3&q ...
- 为nginx增加nginx_http_concat模块
为nginx增加nginx_http_concat模块 时间 2013-06-05 22:14:56 我行我思 原文 http://www.fanjun.me/?p=562 主题 Nginx 缘由 ...
- nginx Unit 服务器
转自: https://github.com/nginx/unit/pull/18/ 感谢: https://www.v2ex.com/t/389528 English 简体中文 繁體中文 NGINX ...
- NodeJS 模块开发及发布详解
NodeJS 是一门年轻的语言,扩展模块并不太全,经常我们想用某个模块但是却找不到合适的.比如前两天我需要使用hmac和sha1来做签名,就没有找到一个比较好用的模块,这时候就需要我们自己来实现相应的 ...
- nginx利用geo模块做限速白名单以及geo实现全局负载均衡的操作记录
geo指令使用ngx_http_geo_module模块提供的.默认情况下,nginx有加载这个模块,除非人为的 --without-http_geo_module.ngx_http_geo_modu ...
- Nginx做NodeJS应用负载均衡配置实例
这篇文章主要介绍了Nginx做NodeJS应用负载均衡配置实例,本文直接给出配置实例,需要的朋友可以参考下. 负载均衡可以把用户的请求分摊到多个服务器上进行处理,从而实现了对海量用户的访问支持.负载均 ...
- php5.5安装及phpmyadmin&nginx配置php模块
安装php5.5: 下载源地址:rpm -Uvh rpm包安装:yum install php55w.x86_64 php55w-cli.x86_64 php55w-common.x86_64 php ...
- Nginx SPDY Pagespeed模块编译——加速网站载入
在看<Web性能权威指南>的时候,看到了SPDY这货,于是便开始折腾起了这个了,也顺便把pagespeed加了进去. Nginx SPDY 引自百科~~ SPDY(读作“SPeeDY”)是 ...
随机推荐
- LeetCode--176--第二高的薪水
问题描述: 编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) . +----+--------+ | Id | Salary | +----+--------+ | 1 ...
- 使用与不使用@RequestBody注解的区别
1. 如果使用@RequestBody接受页面参数: public Map<String,Object> insertBudget(@ApiParam(required = true,na ...
- python-day30--粘包
一. 什么是粘包 1.须知:只有TCP有粘包现象,UDP永远不会粘包 2.所谓粘包问题主要还是因为接收方不知道消息之间的界限,不知道一次性提取多少字节的数据所造成的. 二.两种情况下会发生粘包. 1. ...
- thinkphp数组处理
1.array_unique() 移除数组中的重复的值,并返回结果数组.当几个数组元素的值相等时,只保留第一个元素,其他的元素被删除,对每个值只保留第一个遇到的键名,接着忽略所有后面的键名.返回的数组 ...
- UVA-1374 Power Calculus (迭代加深搜索)
题目大意:问最少经过几次乘除法可以使x变成xn. 题目分析:迭代加深搜索. 代码如下: # include<iostream> # include<cstdio> # incl ...
- C++ string类与scanf和printf
string要用cin和cout输入和输出. 如果一定要用scanf和printf的话,格式为: s.resize(20);scanf("%s", &s[0]); prin ...
- iOS UI-表格控制器(UITableView)-基本使用
tableView的常见属性 cell的常见属性 一.一般情况 #import "ViewController.h" @interface ViewController ()< ...
- 使用iview-project 打包build报错,ERROR in xxxxx.cheunk.js from UglifyJs
一.iview-project 为iview官方推荐工程,一个基于iview的vue脚手架 github网址:https://github.com/iview/iview-project 废话不多说 ...
- forget words out1
forget word 1● information 2● infomation 3● mation 4● pavilion 5● river 6● mouth 7● fish 8● lick 9● ...
- hdu 1556 Color the ball (线段树+代码详解)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...