generated from nginx/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 120
feat: Set up config templates for N1 Console #1233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dbff288
Content from F5 user vrmare in internal repo
mjang 8b23ff2
Update content/nginx-one/nginx-configs/config-templates/author-templa…
mjang bbda9a0
Update content/nginx-one/nginx-configs/config-templates/import-templa…
mjang 3b22f5a
Update content/nginx-one/nginx-configs/config-templates/author-templa…
mjang fe985c9
Add changelog
mjang 20936f1
Apply suggestions from code review
mjang a0c0de2
Apply suggestions from code review
mjang 4652a07
Merge branch 'main' into feat-release-n1-console-templates-r1
mjang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
description: | ||
title: Manage config templates | ||
weight: 400 | ||
url: /nginx-one/nginx-configs/config-templates | ||
--- |
303 changes: 303 additions & 0 deletions
303
content/nginx-one/nginx-configs/config-templates/add-multiple-services.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,303 @@ | ||
--- | ||
nd-docs: null | ||
title: Add service-specific locations | ||
toc: true | ||
weight: 400 | ||
type: | ||
- how-to | ||
--- | ||
|
||
# Overview | ||
|
||
This guide shows how to extend working submission from the [Submit Templates Guide]({{< ref "submit-templates.md" >}}) by adding server augments for new services with dedicated location augments. | ||
mjang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
**Note: With current limitation to not being able to retrieve previous submissions, you must provide entire request including any updates.** | ||
mjang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
## Import template | ||
|
||
If there aren't existing augment templates that fit your needs, you will need to create and import them. | ||
|
||
### New server augment template | ||
|
||
Since we don't have a server augment yet, we need to create one. This template creates dedicated server blocks for each service. | ||
mjang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
`http-server.tmpl` | ||
|
||
```text | ||
server { | ||
listen {{ .listen_port }}; | ||
server_name{{ range .server_names }} {{ . }}{{ end }}; | ||
|
||
{{ augment_includes "http/server/location" . }} | ||
} | ||
``` | ||
|
||
`schema.yaml` | ||
|
||
```text | ||
$schema: "http://json-schema.org/draft-07/schema#" | ||
type: object | ||
properties: | ||
listen_port: | ||
type: integer | ||
description: "Port for the server to listen on" | ||
minimum: 1 | ||
maximum: 65535 | ||
default: 80 | ||
server_names: | ||
type: array | ||
description: "Array of domain names for this server" | ||
items: | ||
type: string | ||
minItems: 1 | ||
required: | ||
- listen_port | ||
- server_names | ||
additionalProperties: false | ||
``` | ||
|
||
#### Import parameters | ||
|
||
When [Importing]({{< ref "import-templates.md#ready-to-import" >}}) this template: | ||
mjang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
- name: `http-server` | ||
- type: `augment` | ||
- allowed_in_contexts: `["http"]` | ||
|
||
### New location augment template | ||
|
||
We also need a location augment template to create location blocks within each server. | ||
mjang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
{{< call-out "note" >}} | ||
You may already have a "health-check" location augment from previous steps which can be added to these new servers as well.* | ||
{{< /call-out >}} | ||
mjang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
`location-proxy.tmpl` | ||
|
||
```text | ||
location {{ .path }} { | ||
proxy_pass {{ .upstream_url }}; | ||
proxy_connect_timeout {{ .proxy_timeout }}; | ||
proxy_read_timeout {{ .proxy_read_timeout }}; | ||
} | ||
``` | ||
|
||
`schema.yaml` | ||
|
||
```text | ||
$schema: "http://json-schema.org/draft-07/schema#" | ||
type: object | ||
properties: | ||
path: | ||
type: string | ||
description: "Location path (e.g., /api, /admin)" | ||
mjang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
pattern: "^/.*$" | ||
upstream_url: | ||
type: string | ||
description: "Backend service URL" | ||
pattern: "^https?://[^\\s]+$" | ||
proxy_timeout: | ||
type: string | ||
description: "Proxy connection timeout" | ||
pattern: "^\\d+[smhd]?$" | ||
default: "30s" | ||
proxy_read_timeout: | ||
type: string | ||
description: "Proxy read timeout" | ||
pattern: "^\\d+[smhd]?$" | ||
default: "60s" | ||
required: | ||
- path | ||
- upstream_url | ||
additionalProperties: false | ||
``` | ||
|
||
#### Import parameters | ||
When [Importing]({{< ref "import-templates.md#ready-to-import" >}}) this template: | ||
mjang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
- name: `location-proxy` | ||
- type: `augment` | ||
- allowed_in_contexts: `["http/server/location"]` | ||
|
||
## Submit to add multiple services | ||
|
||
### Request structure | ||
|
||
Here's an example of what you need to include with the API request: | ||
mjang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
```json | ||
{ | ||
"conf_path": "/etc/nginx/nginx.conf", | ||
"base_template": { | ||
"object_id": "<id of your template object>", | ||
mjang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
"values": { | ||
"backend_url": "http://example.com:8080" | ||
} | ||
}, | ||
"augments": [ | ||
{ | ||
"object_id": "<id of your template object>", | ||
mjang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
"target_context": "http/server/location", | ||
"values": { | ||
"cors_allowed_origins": "https://app.example.com", | ||
"cors_allowed_methods": "GET, POST, PUT, DELETE, OPTIONS" | ||
} | ||
}, | ||
{ | ||
"object_id": "<id of your template object>", | ||
"target_context": "http/server" | ||
}, | ||
{ | ||
"object_id": "<id of your template object>", | ||
"target_context": "http", | ||
"values": { | ||
"listen_port": 80, | ||
"server_names": ["admin.example.com"] | ||
}, | ||
"child_augments": [ | ||
{ | ||
"object_id": "<id of your template object>", | ||
"target_context": "http/server/location", | ||
"values": { | ||
"path": "/admin", | ||
"upstream_url": "http://admin-backend:8080" | ||
} | ||
}, | ||
{ | ||
"object_id": "<id of your template object>", | ||
"target_context": "http/server/location", | ||
"values": { | ||
"health_check_path": "/admin/health" | ||
mjang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
``` | ||
|
||
### What's in your new config template | ||
|
||
- **Existing augments remain:** Your CORS headers and health check continue to apply to the main server | ||
- **New server augments:** You'll see an additional server block | ||
- **Service-specific routing:** You'll find the new `admin.example.com` server name with its own location blocks and routing rules | ||
mjang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
### Response format | ||
|
||
When you submit the request, you'll see the following results if you're successful, along with the rendered NGINX configuration: | ||
mjang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
#### Successful response (200 OK) | ||
|
||
```json | ||
{ | ||
"config": { | ||
"aux": [], | ||
"conf_path": "/etc/nginx/nginx.conf", | ||
"config_version": "nuZ4+d1T159/0vVV9vKaajrEw7QXc6T3fAnxKcVkC6I=", | ||
"configs": [ | ||
{ | ||
"files": [ | ||
{ | ||
"contents": "<base64_encoded_nginx_conf>", | ||
"mtime": "0001-01-01T00:00:00Z", | ||
"name": "nginx.conf", | ||
"size": 483 | ||
} | ||
], | ||
"name": "/etc/nginx" | ||
}, | ||
{ | ||
"files": [ | ||
{ | ||
"contents": "<base64_encoded_nginx_conf>", | ||
"mtime": "0001-01-01T00:00:00Z", | ||
"name": "cors-headers.tmpl.4aaf36d4a643.conf", | ||
"size": 159 | ||
}, | ||
{ | ||
"contents": "<base64_encoded_nginx_conf>", | ||
"mtime": "0001-01-01T00:00:00Z", | ||
"name": "health-check.tmpl.78346de4dae4.conf", | ||
"size": 109 | ||
}, | ||
{ | ||
"contents": "<base64_encoded_nginx_conf>", | ||
"mtime": "0001-01-01T00:00:00Z", | ||
"name": "http-server.tmpl.81761e94d463.conf", | ||
"size": 145 | ||
}, | ||
{ | ||
"contents": "<base64_encoded_nginx_conf>", | ||
"mtime": "0001-01-01T00:00:00Z", | ||
"name": "location-proxy.tmpl.66ebf3e1dfd9.conf", | ||
"size": 121 | ||
} | ||
], | ||
"name": "/etc/nginx/conf.d/augments" | ||
} | ||
] | ||
}, | ||
"errors": null | ||
} | ||
``` | ||
|
||
#### Rendered NGINX configuration | ||
|
||
```nginx | ||
# configuration file /etc/nginx/nginx.conf: | ||
user nginx; | ||
worker_processes auto; | ||
|
||
events { | ||
worker_connections 1048; | ||
} | ||
|
||
http { | ||
server { | ||
listen 80; | ||
server_name admin.example.com; | ||
|
||
location /admin { | ||
proxy_pass http://admin-backend:8080; | ||
proxy_connect_timeout 30s; | ||
proxy_read_timeout 60s; | ||
} | ||
|
||
} | ||
|
||
|
||
server { | ||
listen 80; | ||
server_name _; | ||
|
||
location /health { | ||
access_log off; | ||
return 200 "healthy\n"; | ||
add_header Content-Type text/plain; | ||
} | ||
|
||
|
||
location / { | ||
proxy_pass http://example.com:8080; | ||
add_header 'Access-Control-Allow-Origin' 'https://app.example.com' always; | ||
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always; | ||
|
||
} | ||
} | ||
} | ||
``` | ||
|
||
## Child augments | ||
|
||
Child augments allow you to nest augments within other augments, creating hierarchical configurations. This is commonly used when an augment creates a container (like a server block) that needs its own specific sub-configurations (like location blocks). | ||
|
||
**How Child Augments Work:** | ||
|
||
When an augment template includes an `{{ augment_includes "context_path" . }}` extension point, you can provide child augments that target that context path. The child augments render only within their parent augment's output. | ||
|
||
**Key Behavior:** | ||
- Child locations only apply to their specific parent server | ||
- Multiple servers can have different location configurations | ||
- Each server operates independently with its own routing rules | ||
|
||
For information on designing templates with extension points, see the [Template Authoring Guide]({{< ref "author-templates.md" >}}). | ||
mjang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.