Skip to content

Instantly share code, notes, and snippets.

@nginx-gists
Last active November 11, 2022 00:12
Show Gist options
  • Save nginx-gists/d05b0682818b34c6691105b16fac641a to your computer and use it in GitHub Desktop.
Save nginx-gists/d05b0682818b34c6691105b16fac641a to your computer and use it in GitHub Desktop.
Announcing NGINX Plus R10
server {
listen 443 ssl;
server_name example.com;
ssl_certificate example.com.rsa.crt;
ssl_certificate_key example.com.rsa.key;
ssl_certificate example.com.ecdsa.crt;
ssl_certificate_key example.com.ecdsa.key;
}
# vim: syntax=nginx
function leftpad(r) {
// Pull function arguments from the query string
var str, len, ch;
for (a in r.args) {
if (a == "str") str = String(r.args[a]);
if (a == "len") len = r.args[a];
if (a == "ch") ch = r.args[a];
}
// Do the padding
var i = -1;
if (!ch && ch !== 0) ch = ' ';
len = len - str.length;
while (++i < len) {
str = ch + str;
}
// Construct complete HTTP response
var res = r.response;
res.headers.rpc-method = "leftpad";
res.status = 200;
res.contentType = 'text/plain; charset=utf-8';
res.contentLength = str.length + 1; // Plus newline
res.sendHeader();
res.send(str + 'n');
res.finish();
}
export default { leftpad }
server {
listen 80;
location / {
auth_jwt "myrealm";
auth_jwt_key_file /etc/nginx/jwt_keyfiles/secret.jwk;
proxy_pass http://backend_app;
add_header Authenticated-User $jwt_claim_sub;
}
}
# vim: syntax=nginx
load_module modules/ngx_http_modsecurity.so;
http {
upstream backend {
server <server-hostname>;
}
server {
listen 80;
status_zone backend;
modsecurity on;
location / {
proxy_pass http://backend;
modsecurity_rules_file <rule-set-file>;
}
}
}
# vim: syntax=nginx
load_module modules/<module-name>.so;
load_module modules/ngx_http_js_module.so;
load_module modules/ngx_stream_js_module.so;
http {
js_import conf.d/functions.js;
server {
listen 80;
location /functions/leftpad {
js_content functions.leftpad;
}
}
}
# vim: syntax=nginx
stream {
upstream dns {
server dns1.example.com:53;
server dns2.example.com:53;
}
server {
listen 53 udp;
proxy_bind $remote_addr:$remote_port transparent;
proxy_responses 0; # Don’t expect to see any responses from upstream
proxy_pass dns;
}
}
# vim: syntax=nginx
@nginx-gists
Copy link
Author

For a discussion of these files, see Announcing NGINX Plus R10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment