通过 docker 安装
$ docker pull nginx/unit
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest f7bb5701a33c 9 days ago 126MB
nginx/unit latest c3609c1acd08 11 days ago 236MB
hello-world latest fce289e99eb9 12 months ago 1.84kB
启动一个 nginx unit 容器
$ docker run -d nginx/unit
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c386d83835f9 c3609c1acd08 "/usr/local/bin/dock…" 15 hours ago Up 42 minutes 0.0.0.0:8001->8001/tcp stoic_snyder
进入 nginx unit 容器
$ docker exec -it c3 /bin/bash
root@c386d83835f9:/#
配置 nginx unit
root@ip-172-31-46-207:/# unitd --control 127.0.0.1:8000
2020/01/07 08:53:45 [info] 22#22 unit started
root@ip-172-31-46-207:/# 2020/01/07 08:53:45 [info] 24#24 discovery started
2020/01/07 08:53:45 [notice] 24#24 module: perl 5.28.1 "/usr/lib/unit/modules/perl.unit.so"
2020/01/07 08:53:45 [notice] 24#24 module: php 7.3.4-2 "/usr/lib/unit/modules/php.unit.so"
2020/01/07 08:53:45 [notice] 24#24 module: python 2.7.16 "/usr/lib/unit/modules/python2.7.unit.so"
2020/01/07 08:53:45 [notice] 24#24 module: python 3.7.3 "/usr/lib/unit/modules/python3.7.unit.so"
2020/01/07 08:53:45 [notice] 24#24 module: ruby 2.5.5 "/usr/lib/unit/modules/ruby.unit.so"
2020/01/07 08:53:45 [notice] 23#23 process 24 exited with code 0
2020/01/07 08:53:45 [info] 26#26 router started
2020/01/07 08:53:45 [info] 26#26 OpenSSL 1.1.1d 10 Sep 2019, 1010104f
root@ip-172-31-46-207:/# exit
ubuntu@ip-172-31-46-207:~/projects$ curl 127.0.0.1:8000
{
"certificates": {},
"config": {
"listeners": {},
"applications": {}
}
}
ubuntu@ip-172-31-46-207:~/projects$ curl -X PUT -d @_projects/nginx.conf 127.0.0.1:8000
{
"error": "Invalid method."
}
ubuntu@ip-172-31-46-207:~/projects$ curl -X PUT -d @_projects/nginx.conf 127.0.0.1:8000/config
2020/01/07 08:56:39 [info] 30#30 "pinpoint" application started
2020/01/07 08:56:39 [info] 30#30 (non ABS_MODE) php root: "/_projects/pinpoint"
{
"success": "Reconfiguration done."
}
ubuntu@ip-172-31-46-207:~/projects$
修改配置
ubuntu@ip-172-31-46-207:~/projects$ cat nginx.conf
{
"listeners": {
"127.0.0.1:80": {
"pass": "applications/pinpoint"
}
},
"applications": {
"pinpoint": {
"type": "php",
"root": "/_projects/pinpoint",
"index": "index.php"
}
}
}
ubuntu@ip-172-31-46-207:~/projects$ curl -X PUT -d @nginx.conf 127.0.0.1:8000/config
{
"error": "Failed to apply new configuration."
}
ubuntu@ip-172-31-46-207:~/projects$