nginx unit PHP

2018-12-26 14:20:33 星期三php

综述: nginx unit php 的关系: nginx

nginx -> 转发请求到 8300端口 -> unit 转发 8300 收到的请求 -> PHPjson

首先, 配置unit, 设置转发哪一个端口的请求, 转发给哪一个PHP文件, PHP的配置文件地址, 启动的进程数等centos

而后, 配置nginx, 将匹配到的域名/ip/端口, 经过 proxy 相关指令转发到 unit监听并转发的端口app

而unit自己也还会监听某一个端口或sock文件, 用来接收配置信息的更改请求curl

 

具体操做socket

第一步: 安装, 我用的是centos 6 官网 http://unit.nginx.org/installation/#centos-packagesurl

 

第二步: 启动 若是是按照官网, 经过yum 进行安装的, 启动方法就是spa

/usr/sbin/unitd --control 127.0.0.1:8224
2018/12/26 14:26:11 [info] 13924#13924 unit started

此时unix

ps -ef | grep unit
root     13777     1  0 14:03 ?        00:00:00 unit: main v1.7 [/usr/sbin/unitd --control 127.0.0.1:8224]
nobody   13779 13777  0 14:03 ?        00:00:00 unit: controller
nobody   13896 13777  0 14:14 ?        00:00:00 unit: router

 

第三步: 建立配置文件 , 复制并修改官网的json, 建立json文件: /etc/unit/test.json

{
    "listeners": {
        "*:8300": {
            "application": "test"
        }
    },

    "applications": {
        "test": {
            "type": "php",
            "processes": 2,
            "root": "/www/unit/test",
            "index": "index.php"
            
        }
    }
}

第四步: 用curl命令将这个json文件发送给unit, 建立对象 (注意官网是经过 unix-socket 进程间通讯的方法去发送json配置文件给unit的守护进程的, 在这里直接发送到unit监听的端口)

curl -X PUT -d @/etc/unit/test.json  http://localhost:8224/config 

此时多了两个application进程:

ps -ef | grep unit
root     13925     1  0 14:26 ?        00:00:00 unit: main v1.7 [/usr/sbin/unitd]
nobody   13927 13925  0 14:26 ?        00:00:00 unit: controller
nobody   13928 13925  0 14:26 ?        00:00:00 unit: router
root     13929 13925  0 14:26 ?        00:00:00 unit: "test" application
root     13930 13925  0 14:26 ?        00:00:00 unit: "test" application

 

第五步: 查看已发送的配置

curl http://127.0.0.1:8224

 

第六步: 更改json配置文件, 进程数设置为5, 并从新发送配置, 再查看进程数: application进程变为5个

ps -ef | grep unit
root     13983     1  0 14:48 ?        00:00:00 unit: main v1.7 [/usr/sbin/unitd --control 127.0.0.1:8224]
nobody   13985 13983  0 14:48 ?        00:00:00 unit: controller
nobody   13986 13983  0 14:48 ?        00:00:00 unit: router
root     13993 13983  0 14:49 ?        00:00:00 unit: "test" application
root     13994 13983  0 14:49 ?        00:00:00 unit: "test" application
root     13995 13983  0 14:49 ?        00:00:00 unit: "test" application
root     13996 13983  0 14:49 ?        00:00:00 unit: "test" application
root     13997 13983  0 14:49 ?        00:00:00 unit: "test" application

 

未完待续.....

相关文章
相关标签/搜索