安装介绍:

https://www.oschina.net/p/nginx-unit

可以看到,unit还是很强大的,居然特么都支持go 还有python

在/etc/yum.repos.d/unit.repo加入如下语句:

# cat /etc/yum.repos.d/unit.repo
[unit]
name=unit repo
baseurl=https://packages.nginx.org/unit/centos/$releasever/$basearch/
gpgcheck=
enabled=
# 

makecache yum源

# yum makecache

执行安装 由于要测试unit-php,故安装unit-php ,如果要测试python,可以安装unit-python,如果要测试go,则安装unit-go

# yum install unit unit-php

这里有坑,安装unit-php的时候,默认就安装了5.3的

所以,如果你自己安装了php7的,调用phpinfo的时候,会显示php 5.3 ,原因在此,这个得需要源码安装,有点坑,过几天再去踩踩

编辑配置文件

编辑配置文件,内容如下:

# cat /etc/unit/start.json
{
    "listeners": {
        "*:8300": {
            "application": "blogs"
        }
    },

    "applications": {
        "blogs": {
            "type": "php",
            ,
            "root": "/usr/local/nginx/php",
            "index": "index.php"
        }
    }
}
# 

启动unit并且加载json文件

# /etc/init.d/unit start

# /usr/local/bin/curl -X PUT -d @/etc/unit/start.json --unix-socket /var/run/control.unit.sock http://localhost
{
"success": "Reconfiguration done."
}

当出现success": "Reconfiguration done.则怎么加载成功,可以用netstat查看端口是否已经开起来

注意,这里有坑,如果要用curl的unix-socket参数,若curl包低于7.4需要进行升级

curl下载地址:https://curl.haxx.se/download/

例如,如下安装方法:

# wget https://curl.haxx.se/download/curl-7.55.0.tar.gz
...解压,进入目录...
# ./configure
# make
# make install
如果在编译的时候不指定安装目录,则会安装到/usr/local/bin下面
查看版本
# /usr/local/bin/curl --version
curl  (x86_64-pc-linux-gnu) libcurl/ OpenSSL/
Release-Date: --
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: IPv6 Largefile NTLM NTLM_WB SSL libz UnixSockets HTTPS-proxy
# 

查看加载的配置

# /usr/local/bin/curl --unix-socket /var/run/control.unit.sock http://localhost
{
    "listeners": {
        "*:8300": {
            "application": "blogs"
        }
    },

    "applications": {
        "blogs": {
            "type": "php",
            ,
            "root": "/usr/local/nginx/php",
            "index": "index.php"
        }
    }
}
# 

这时候,通过netstat可以看到8300端口已经打开了,

# cat /usr/local/nginx/php/index.php
<?php
    phpinfo();
?>
# 

通过8300访问,就可以看看到phpinfo的界面了,但是前提是,root下,必须有index.php哟

重新加载配置文件

重新编写配置文件

# cat /etc/unit/start.json
{
    "listeners": {
        "*:8300": {
            "application": "blogs"
        }
    },

    "applications": {
        "blogs": {
            "type": "php",
            ,
            "root": "/usr/local/nginx/php",
            "index": "index.php",

        "user": "php",
        "group": "php",

        "options": {
            "file": "/usr/local/php7/lib/php.ini"
        }
        }
    }
}
#

重新加载配置文件

# /usr/local/bin/curl -X PUT -d @/etc/unit/start.json --unix-socket /var/run/control.unit.sock http://localhost
{
"success": "Reconfiguration done."
}

再次查看配置文件

# /usr/local/bin/curl --unix-socket /var/run/control.unit.sock http://localhost
{
    "listeners": {
        "*:8300": {
            "application": "blogs"
        }
    },

    "applications": {
        "blogs": {
            "type": "php",
            ,
            "root": "/usr/local/nginx/php",
            "index": "index.php",
            "user": "php",
            "group": "php",
            "options": {
                "file": "/usr/local/php7/lib/php.ini"
            }
        }
    }
}
# 

这时候,可以通过页面,访问如下信息:

Nginx proxy_pass设置

只需要在location中添加如下几项即可

proxy_pass http://127.0.0.1:8300;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

检查语法,重启nginx

# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
# /usr/local/nginx/sbin/nginx -s reload
# 

通过Nginx访问界面如下:

可以看到,Server API 是unit

总结:

  0.参考网址:http://unit.nginx.org/

  1.unit 目前用的还很少,主流依然是php-fpm

  2.如果能够采用源码编译unit的话,当然是最好的

  3.curl版本问题

  4.编写的json文件格式一定要正确,可以用在线工具检测json是否正确(http://www.bejson.com/)

兴趣才是最好的老师,加油吧。。。这玩意快搞了我加起来两天时间了,

nginx unit的初探的更多相关文章

  1. svn + nginx unit + python3自动化发布web服务方法

    本周将python web服务管理更换成nginx unit以后发现接口性能有了明显的提升,访问速度快了不少.不过有个很大的问题就是使用svn自动化发布以后,服务并没有刷新使用新的代码运行,而又不懂得 ...

  2. 关于nginx unit服务非正常关闭后,无法重新启动问题的处理

    昨天在前领导技术大牛吕哥的帮忙下,python服务管理从nginx+supervisor+uwsgi+python3改为了轻便结构nginx + unit + python3,部署和配置起来顿时轻松起 ...

  3. nginx unit PHP

    2018-12-26 14:20:33 星期三 综述: nginx unit php 的关系: nginx -> 转发请求到 8300端口 -> unit 转发 8300 收到的请求 -& ...

  4. Nginx unit 源码安装初体验

    Nginx unit 源码安装初体验 上次介绍了从yum的安装方法(https://www.cnblogs.com/wang-li/p/9684040.html),这次将介绍源码安装,目前最新版为1. ...

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

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

  6. nginx unit nodejs 模块试用

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

  7. nginx Unit 服务器

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

  8. nginx unit java 试用

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

  9. nginx unit 的使用

    参考文档:http://unit.nginx.org/configuration/# 安装 可以参考这两篇博客: https://www.cnblogs.com/wang-li/p/9694391.h ...

随机推荐

  1. Percona MySQL 5.7 Linux通用二进制包安装(CentOS 6)

    Linux 安装 Percona http://blog.itpub.net/26506993/viewspace-2136501/ https://www.cnblogs.com/snowwhite ...

  2. Dubbo源码解析之registry注册中心

    阅读须知 dubbo版本:2.6.0 spring版本:4.3.8 文章中使用/* */注释的方法会做深入分析 正文注册中心是Dubbo的重要组成部分,主要用于服务的注册与发现,我们可以选择Redis ...

  3. spring boot 错误处理之深度历险

    今天终于把 boot 的异常处理完全研究透了: boot提供了很多错误的处理工作.默认情况下,我们会看到一个whiteLabel(白标)的页面. 这个可能不是我们所需.因此我们需要定制.我于是做了个深 ...

  4. 什么是python的全局解释锁(GIL)

    GIL解决了Python中的什么问题? 为什么选取GIL作为解决方案? 对多线程Python程序的影响 为什么GIL还没有被删除? 为什么在Python 3 中GIL没有被移除? 如何处理Python ...

  5. JRebel 代理激活

    1.生成GUID   https://www.guidgen.com/ 例:04cfff79-8f45-481c-a858-a5b9590422e7 2.License Server 例: http: ...

  6. Elasticsearch 整合spring(不是sprig boot)

    公司做统计任务,有使用Es做聚合操作,使用的是自己封装的版本,这边整合下原生spring,做下学习记录,随便看一下,发现差不多都是spring boot的案例...我该怎么办,...发现整合的过程其实 ...

  7. Web页面长时间无操作后再获取焦点时转到登录界面

    今天开始讲新浪博客搬到博客园.        在工作中遇到的小问题,感觉有点意思,就记录下来吧!        该问题分为两种情况,一.Web页面长时间无操作后,在对其进行操作,比如点击“首页”.“设 ...

  8. vue初体验

    作为一个前端的小菜鸟,在平时的开发与学习中,除了要深入了解javascript 及 css 的各种特性,熟悉一门框架也是必不可少的.vue以其小巧,轻便,学习平滑等各种特性深受欢迎. 这里总结一下小菜 ...

  9. day39 mysql数据库基本操作

    什么是数据库 用来存储数据的仓库 数据库可以在硬盘及内存中存储数据 主要学习硬盘中存储数据,因为内存中的数据总有一天会丢失 数据库与文件存储数据区别 (公司的开发是综合内容的) 数据库本质也是通过文件 ...

  10. nlp算法工程师养成记 目标要求

    时间规定: 2018.12.07-2018.02.15 能力养成: linux, shell python, c++(会多少算多少) tensorflow, keras, pytorch(tf优先) ...