Skip to content

Instantly share code, notes, and snippets.

@nginx-gists
nginx-gists / ubuntu_install.sh
Last active May 4, 2024 19:32
Automating Installation of WordPress with NGINX Unit on Ubuntu
#!/usr/bin/env bash
if [ "$EUID" -ne 0 ];then
>&2 echo "This script requires root level access to run"
exit 1
fi
if [ -z "${WORDPRESS_DB_PASSWORD}" ]; then
>&2 echo "WORDPRESS_DB_PASSWORD must be set"
>&2 echo "Here is a random one that you can paste:"
@nginx-gists
nginx-gists / api_backends.conf
Last active April 21, 2024 09:19 — forked from lcrilly/api_backends.conf
Deploying NGINX Plus as an API Gateway, Part 1
upstream warehouse_inventory {
zone inventory_service 64k;
server 10.0.0.1:80;
server 10.0.0.2:80;
server 10.0.0.3:80;
}
upstream warehouse_pricing {
zone pricing_service 64k;
server 10.0.0.7:80;
@nginx-gists
nginx-gists / auth_request.conf
Last active February 26, 2024 13:10
Validating OAuth 2.0 Access Tokens with NGINX and NGINX Plus
server {
listen 80;
location / {
auth_request /_oauth2_token_introspection;
proxy_pass http://my_backend;
}
location = /_oauth2_token_introspection {
internal;
@nginx-gists
nginx-gists / Dockerfile
Last active February 17, 2024 01:34
Dockerfiles for NGINX Plus R31 (Debian bookworm -12- and Alpine Linux 3.19), from “Deploying NGINX and NGINX Plus with Docker”
ARG RELEASE=bookworm
FROM debian:${RELEASE}-slim
LABEL maintainer="NGINX Docker Maintainers <docker-maint@nginx.com>"
# Define NGINX versions for NGINX Plus and NGINX Plus modules
# Uncomment this block and the versioned nginxPackages block in the main RUN
# instruction to install a specific release
# ARG RELEASE
# ENV NGINX_VERSION 31
@nginx-gists
nginx-gists / banned.html
Last active November 9, 2023 09:43
Dynamic IP Denylisting with NGINX Plus and fail2ban
<!DOCTYPE html>
<html>
<head>
<title>Banned</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
@nginx-gists
nginx-gists / nlk_openid_frontend.conf
Created September 14, 2023 19:12
NLK OpenID integration
# This is the backend application we are protecting with OpenID Connect
upstream cluster1-https {
zone cluster1-https 256k;
least_time last_byte;
keepalive 16;
#servers managed by NKL Controller
state /var/lib/nginx/state/cluster1-https.state;
}
# Custom log format to include the 'sub' claim in the REMOTE_USER field
@nginx-gists
nginx-gists / Dockerfile
Last active September 9, 2023 15:37
Our Roadmap for QUIC and HTTP3 Support in NGINX
# Builds NGINX from the QUIC+HTTP/3 development branch
# - Based on the official NGINX docker image, including all modules built by default
# - OpenSSL replaced with LibreSSL to support QUIC's TLS requirements (statically linked)
#
# docker build --no-cache -t nginx:quic .
# docker run -d -p 443:443 -p 443:443/udp nginx:quic
#
# Note that a suitable configuration file and TLS certificates are required for testing!
# See <https://quic.nginx.org/readme.html> for more info
@nginx-gists
nginx-gists / app-virtual-server.yaml
Created August 13, 2021 22:12
Deploying NGINX Ingress Controller on Amazon EKS: How We Tested
apiVersion: k8s.nginx.org/v1
kind: VirtualServer
metadata:
name: app-ingress
spec:
host: app.example.com
tls:
secret: app-secret-ecc
upstreams:
- name: web-server-payload
@nginx-gists
nginx-gists / mqtt_client_auth.js
Last active March 21, 2023 12:53
NGINX Plus for the IoT: Encrypting and Authenticating MQTT Traffic
function parseCSKVpairs(cskvpairs, key) {
if ( cskvpairs.length ) {
var kvpairs = cskvpairs.split(',');
for ( var i = 0; i < kvpairs.length; i++ ) {
var kvpair = kvpairs[i].split('=');
if ( kvpair[0].toUpperCase() == key ) {
return kvpair[1];
}
}
}
@nginx-gists
nginx-gists / batch-api-min.conf
Last active February 16, 2023 03:01
Batching API Requests with NGINX Plus and the NGINX JavaScript Module
js_import batch-api-min.js;
# keyval_zone for APIs where the last portion of the URI is an argument
# The key is the portion of the URL before the last part
keyval_zone zone=batch_api:64k state=/etc/nginx/state-files/batch-api.json;
keyval $uri_prefix $batch_api zone=batch_api;
# keyval_zone for APIs where the last portion of the URI is an argument
# The key is the URI
keyval_zone zone=batch_api2:64k state=/etc/nginx/state-files/batch-api2.json;