Comments (17)
There are 3 methods supported at the moment: GET
, PUT
, DELETE
. You can operate over the configuration root /
as well as any sublayers, like /listeners
, /listeners/IP:PORT
, /listeners/IP:PORT/application
, /applications
, /applications/NAME
, /applications/NAME/workers
, etc...
from unit.
You can add an application and then a listener, thus with two requests. For now, there's only one way to add both a listener and an application with just one request: by uploading the full resulting configuration to the root /
.
Support for the MERGE/PATCH
methods in conformity with RFC 7396 is planned.
from unit.
I also can suggest a nice and very powerful utility for operating with JSON:
% cat conf.json
{
"listeners": {
"127.0.0.1:8081": {
"application": "test"
}
},
"applications": {
"test": {
"type": "python",
"module": "wsgi",
"path": "/home/vbart/Development/tests"
}
}
}
% <conf.json | jq .applications.test
{
"type": "python",
"module": "wsgi",
"path": "/home/vbart/Development/tests"
}
% <conf.json | jq '.listeners[]'
{
"application": "test"
}
https://stedolan.github.io/jq/
from unit.
And you can merge JSON files with it:
% cat conf.json
{
"listeners": {
"127.0.0.1:8081": {
"application": "test"
}
},
"applications": {
"test": {
"type": "python",
"module": "wsgi",
"path": "/home/vbart/Development/tests"
}
}
}
% cat conf_t.json
{
"listeners": {
"*:8300": {
"application": "php56domaincom"
}
},
"applications": {
"php56domaincom": {
"type": "php",
"workers": 10,
"root": "/home/nginx/domains/domain.com/public",
"user": "vbart",
"group": "users",
"index": "index.php"
}
}
}
% jq -s '.[0] * .[1]' conf.json conf_t.json
{
"listeners": {
"127.0.0.1:8081": {
"application": "test"
},
"*:8300": {
"application": "php56domaincom"
}
},
"applications": {
"test": {
"type": "python",
"module": "wsgi",
"path": "/home/vbart/Development/tests"
},
"php56domaincom": {
"type": "php",
"workers": 10,
"root": "/home/nginx/domains/domain.com/public",
"user": "vbart",
"group": "users",
"index": "index.php"
}
}
}
from unit.
Yes, you have to define it in URI: /listeners/*:8300
from unit.
Merging with jq
also works fine:
% jq -s '.[0] * .[1]' conf.json conf_t.json | curl -X PUT -d@- http://127.0.0.1:8443
{
"success": "Reconfiguration done."
}
% curl http://127.0.0.1:8443
{
"listeners": {
"127.0.0.1:8081": {
"application": "test"
},
"*:8300": {
"application": "php56domaincom"
}
},
"applications": {
"test": {
"type": "python",
"module": "wsgi",
"path": "/home/vbart/Development/tests"
},
"php56domaincom": {
"type": "php",
"workers": 10,
"root": "/home/nginx/domains/domain.com/public",
"user": "vbart",
"group": "users",
"index": "index.php"
}
}
}
from unit.
That error comes from nginx, not unit. =)
Note, that I used curl
command without unix socket, because I run my Unit with control socket set to 127.0.0.1:8443
.
from unit.
If you have the modules collection that you mentioned in #47, then php 7.1.9
is missing.
from unit.
This state directory isn't a configuration storage. It was introduced just for runtime configuration persistence in order to allow Unit to survive server reloads without additional tricks. It's up to you where to store and how to manage your configurations.
from unit.
i see but even if i do not restart unitd service, i can only list the last added php720start.json
configuration ? the previous 3 configs are gone ?
curl --unix-socket /opt/unit/control.unit.sock http://localhost/
{
"listeners": {
"*:8600": {
"application": "php72domaincom"
}
},
"applications": {
"php72domaincom": {
"type": "php 7.2.0",
"workers": 20,
"root": "/home/nginx/domains/domain.com/public",
"user": "nginx",
"group": "nginx",
"index": "index.php"
}
}
}
unitd.log
2017/09/24 01:04:42 [info] 18356#18356 discovery started
2017/09/24 01:04:42 [notice] 18356#18356 module: php 5.6.31 "/opt/unit/modules/php5631.unit.so"
2017/09/24 01:04:42 [notice] 18356#18356 module: python 2.7.5 "/opt/unit/modules/python.unit.so"
2017/09/24 01:04:42 [notice] 18356#18356 module: php 5.6.31 "/opt/unit/modules/remiphp5631.unit.so"
2017/09/24 01:04:42 [notice] 18356#18356 ignoring /opt/unit/modules/remiphp5631.unit.so module with the same application language version php 5.6.31 as in /opt/unit/modules/php5631.unit.so
2017/09/24 01:04:42 [notice] 18356#18356 module: php 7.0.24RC1 "/opt/unit/modules/remiphp7023.unit.so"
2017/09/24 01:04:42 [notice] 18356#18356 module: php 7.1.10RC1 "/opt/unit/modules/remiphp719.unit.so"
2017/09/24 01:04:42 [notice] 18356#18356 module: php 7.2.0RC2 "/opt/unit/modules/remiphp720.unit.so"
2017/09/24 01:04:42 [info] 18357#18357 controller started
2017/09/24 01:04:42 [info] 18358#18358 router started
2017/09/24 01:04:42 [crit] 18358#18358 epoll_ctl(3, 3, 9) failed (2: No such file or directory)
2017/09/24 01:04:42 [crit] 18357#18357 epoll_ctl(3, 3, 9) failed (2: No such file or directory)
2017/09/24 01:04:42 [notice] 18355#18355 process 18356 exited with code 0
from unit.
They are gone not because of the reload. When you do PUT
command to the root of the configuration /
it's replaced by the provided object. The PUT
has create or replace semantic.
from unit.
hmm the docs at isn't exactly clear on this http://unit.nginx.org/docs-configuration.html#creating-configuration-objects we have to separately add the listener and applications from separate json files ?
from unit.
cheers but don't we need to define the actual listener *:8300
too ?
cat /root/tools/unitconfigs/php5631start.json
{
"listeners": {
"*:8300": {
"application": "php56domaincom"
}
},
"applications": {
"php56domaincom": {
"type": "php 5.6.31",
"workers": 20,
"root": "/home/nginx/domains/domain.com/public",
"user": "nginx",
"group": "nginx",
"index": "index.php"
}
}
}
if contents of /root/tools/unitconfigs/php5631start-app.json
is
cat /root/tools/unitconfigs/php5631start.json | jq .applications.php56domaincom
{
"type": "php 5.6.31",
"workers": 20,
"root": "/home/nginx/domains/domain.com/public",
"user": "nginx",
"group": "nginx",
"index": "index.php"
}
for
curl -X PUT -d @/root/tools/unitconfigs/php5631start-app.json --unix-socket /opt/unit/control.unit.sock http://localhost/applications/php56domaincom
and for /root/tools/unitconfigs/php5631start-listener.json
contents would be
cat /root/tools/unitconfigs/php5631start.json | jq '.listeners[]'
{
"application": "php56domaincom"
}
for
curl -X PUT -d @/root/tools/unitconfigs/php5631start-listener.json --unix-socket /opt/unit/control.unit.sock http://localhost/listeners
??
from unit.
cheers so
curl -X PUT -d @/root/tools/unitconfigs/php5631start-listener.json --unix-socket /opt/unit/control.unit.sock http://localhost/listeners/*:8300
lots to digest.. thanks
Hope this info makes it into official documentation manual too :)
from unit.
@VBart thanks merging seems easier to do as I can script it to read all .json files within a config directory for merging :)
jq -s '.[0] * .[1] * .[2] * .[3] * .[4]' php5631start.json php7024start.json php719start.json php720start.json php7110start.json
{
"listeners": {
"*:8300": {
"application": "php56domaincom"
},
"*:8400": {
"application": "php71domaincom"
},
"*:8600": {
"application": "php72domaincom"
},
"*:8500": {
"application": "php71domaincom"
}
},
"applications": {
"php56domaincom": {
"type": "php 7.1.9",
"workers": 20,
"root": "/home/nginx/domains/domain.com/public",
"user": "nginx",
"group": "nginx",
"index": "index.php"
},
"php70domaincom": {
"type": "php 7.0.24",
"workers": 20,
"root": "/home/nginx/domains/domain.com/public",
"user": "nginx",
"group": "nginx",
"index": "index.php"
},
"php72domaincom": {
"type": "php 7.2.0",
"workers": 20,
"root": "/home/nginx/domains/domain.com/public",
"user": "nginx",
"group": "nginx",
"index": "index.php"
},
"php71domaincom": {
"type": "php 7.1.10",
"workers": 20,
"root": "/home/nginx/domains/domain.com/public",
"user": "nginx",
"group": "nginx",
"index": "index.php"
}
}
}
though getting 405 not allowed error
jq -s '.[0] * .[1] * .[2] * .[3] * .[4]' php5631start.json php7024start.json php719start.json php720start.json php7110start.json | curl -X PUT -d@- http://localhost
<html>
<head><title>405 Not Allowed</title></head>
<body bgcolor="white">
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx</center>
</body>
</html>
from unit.
thanks for the hint added the control socket back
jq -s '.[0] * .[1] * .[2] * .[3] * .[4]' php5631start.json php7024start.json php719start.json php720start.json php7110start.json | curl -X PUT -d@- --unix-socket /opt/unit/control.unit.sock http://localhost/
{
"error": "Invalid configuration."
}
jq -s '.[0] * .[1] * .[2] * .[3] * .[4]' php5631start.json php7024start.json php719start.json php720start.json php7110start.json
{
"listeners": {
"*:8300": {
"application": "php56domaincom"
},
"*:8400": {
"application": "php71domaincom"
},
"*:8600": {
"application": "php72domaincom"
},
"*:8500": {
"application": "php71domaincom"
}
},
"applications": {
"php56domaincom": {
"type": "php 7.1.9",
"workers": 20,
"root": "/home/nginx/domains/domain.com/public",
"user": "nginx",
"group": "nginx",
"index": "index.php"
},
"php70domaincom": {
"type": "php 7.0.24",
"workers": 20,
"root": "/home/nginx/domains/domain.com/public",
"user": "nginx",
"group": "nginx",
"index": "index.php"
},
"php72domaincom": {
"type": "php 7.2.0",
"workers": 20,
"root": "/home/nginx/domains/domain.com/public",
"user": "nginx",
"group": "nginx",
"index": "index.php"
},
"php71domaincom": {
"type": "php 7.1.10",
"workers": 20,
"root": "/home/nginx/domains/domain.com/public",
"user": "nginx",
"group": "nginx",
"index": "index.php"
}
}
}
from unit.
ah ha thanks @VBart needed that second set of eyes :)
jq -s '.[0] * .[1] * .[2] * .[3]' php5631start.json php7024start.json php720start.json php7110start.json | curl -X PUT -d@- --unix-socket /opt/unit/control.unit.sock http://localhost
{
"success": "Reconfiguration done."
}
curl --unix-socket /opt/unit/control.unit.sock http://localhost/
{
"listeners": {
"*:8300": {
"application": "php56domaincom"
},
"*:8400": {
"application": "php70domaincom"
},
"*:8600": {
"application": "php72domaincom"
},
"*:8500": {
"application": "php71domaincom"
}
},
"applications": {
"php56domaincom": {
"type": "php 5.6.31",
"workers": 20,
"root": "/home/nginx/domains/domain.com/public",
"user": "nginx",
"group": "nginx",
"index": "index.php"
},
"php70domaincom": {
"type": "php 7.0.24",
"workers": 20,
"root": "/home/nginx/domains/domain.com/public",
"user": "nginx",
"group": "nginx",
"index": "index.php"
},
"php72domaincom": {
"type": "php 7.2.0",
"workers": 20,
"root": "/home/nginx/domains/domain.com/public",
"user": "nginx",
"group": "nginx",
"index": "index.php"
},
"php71domaincom": {
"type": "php 7.1.10",
"workers": 20,
"root": "/home/nginx/domains/domain.com/public",
"user": "nginx",
"group": "nginx",
"index": "index.php"
}
}
}
from unit.
Related Issues (20)
- How to deubg/log when writing njs scripts and so on? HOT 17
- WASM: Support for Wasi 0.2.0 on wasmtime17 HOT 10
- truncated response when serving big files HOT 15
- Running FastAPI app and getting a Starlette error HOT 8
- Python: Feature request: uvloop support for Python ASGI apps HOT 15
- Feature request: Support application-factory pattern for Python apps HOT 2
- Can't write cache permission denied! HOT 2
- NGINX AlmaLinux permission issues HOT 1
- Incorrect parsing of 64-bit integers HOT 29
- Proxy Grafana Live WebSocket connections
- Add support for writting application logs into stderr when Unit running inside of Docker HOT 5
- Segfault when sending data through nxt_unit_response_write() HOT 13
- test_access_log_keepalive - AssertionError: descriptors leak router HOT 5
- Nginx proxy_pass leading to unit, sometimes outputs 504 HOT 2
- Using Nginx Unit with a ReadOnly filesystem. HOT 5
- Getting strange message when trying to get static files HOT 4
- Add PHP 8.3 image HOT 1
- Does nginx-unit want to support WSGI+ ? HOT 1
- Unit fails to build against njs 0.8.2 and libxml2 2.12, or njs 0.8.3 HOT 3
- ./configure: error: no PHP embed SAPI found when there is no libphp.so HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unit.