CMD_UNIT: Nginx Unit for other handlers (SKINS)(TEMPLATES)

Version 1.62.0

Feature
Finished

BETA This feature is part of the "DirectAdmin Pro Pack" https://docs.directadmin.com/getting-started/pro-pack/overview/ ==== CMD_UNIT https://unit.nginx.org/ Nginx Unit allows for mid-level processing, after the webserver accepts the requests, but can redirect the request with immense control, before it actually hits the disk. =============================== FILES /usr/local/directadmin/data/users/USERNAME/domains/DOMAIN.COM.unit/APP.json /usr/local/directadmin/data/users/USERNAME/domains/DOMAIN.COM.routes/domain|SUB.domain used only for local storage, and to re-fill the live unit daemon. The "live" data is stored/managed in the unit deamon. =============================== TEMPLATES /usr/local/directadmin/data/templates/unit_apps.json /usr/local/directadmin/data/templates/unit_routes.json These 2 templates are just pre-fill values for Users to pick from. Manual editing of raw json is still allowed in the GUI. =============================== =============================== REQUESTS -------- LIST Listing all unit apps and routes: CMD_UNIT?domain=domain.com&json=yes JSON: returns json, with "applications" array. Each app index is the app name, eg "test", and the json data within that app is the data from the domains/domain.com.unit/$NAME.json Note: Numbers are currently shown as string, eg: "timeout": "10" which is set to be fixed such that the container supports actual numbers. "rotues" array[] list is also returned. Will be either: domain.com and/or: sub.domain.com where "subdomain" values are allowed route routes specific to that subdomain. Routes applies to a domain are not applied to that subdomain. ============ APPLICATIONS -------- CREATE APP Creating an nginx unit app Method: POST CMD_UNIT domain=domain.com action=create name=appname #saved as "domain.com_appname" in unit json={ ... your app ... } -------- MODIFY Modify an existing nginx unit app Method: POST domain=domain.com action=modify name=appname json={ ... your app ... } -------- DELETE Method: POST CMD_UNIT json=yes domain=domain.com action=select select0=app1 (select1=app2) DirectAdmin does not check if the app json file currently exists, in case you're attempting to purge a left-over app from curl, which could be out of sync with the files. ============ ROUTES -------- LIST ROUTES Listing all unit apps and routes: CMD_UNIT?domain=domain.com&json=yes -------- ROUTE CREATION STEPS 'GET' the items available to create with: CMD_UNIT?domain=es60-64.com&action=route_create&json=yes CMD_UNIT?domain=es60-64.com&action=route_create&subdomain=sub&json=yes will return; da_settings["applications"] as a list of all currently available unit apps. da_settings["actions"] as a list of possible action (pass,proxy,return,share), with a brief description as each value. route[] the json route currently set for this domain or domain+subdomain. If nothing yet, it will be []. -------- CREATE ROUTE CMD_UNIT method: POST action=set_route domain=domain.com (subdomain=sub :optional is saving for a subdomain) routes=[ the json list of matches/actions for this route ] The "routes" data must be assembled json, as defined here: https://unit.nginx.org/configuration/#routes eg routes= [ { "match": { "uri": "/v2_site/*" }, "action": { "pass": "applications/test.com_php" } }, { "match": { "uri": "/directadmin.com" }, "action": { "return": 301, "location": "https://directadmin.com" } }, { "action": { "proxy": "http://1.2.3.4:9000" } } ] The DirectAdmin back-end recursively parses and validates all aspects of the json to prevent cross-user/domain app calls or shared paths not belonging to this User. -------- DELETE ROUTES CMD_UNIT method: POST json=yes action=select_routes domain=domain.com (even if deleting a sub.domain route, use "domain.com" here) select0=domain.com (select1=sub.domain.com) DA will attempt to clear the route from the unit socket first. If it fails, the local json file will not be removed. If it failed due to the route not existing, the local json file WILL be removed. ==== TODO packages/reseller/user.conf switches directadmin.conf option to disable unit modules, eg: unit_modules=perl:php:etc.. Access Logs for unit. =============================== TASK.QUEUE For a full rewrite of all Unit settings, the dataskq can do it via task.queue file: echo "action=rewrite&value=nginx_unit" >> /usr/local/directadmin/data/task.queue =============================== SKINS files_users.conf: CMD_UNIT_CREATE=user/app/app_create.html CMD_ROUTE_EDIT=user/app/route_edit.html CMD_UNIT=user/app/apps.html also file for viewing all apps, and editing a given app with auto-fill. (Make use of HTM insertion to re-use the same form html file for create and edit) However, we recommend using dynamic json, as Evolution does. The above is only a basic raw textarea json method to control it and does not include the templates like Evo does. ==== EVO1985

Interested to try DirectAdmin? Get a 30-day Free Trial!