Skip to content

Add Lab7 #31

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 11 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions labs/lab7/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,53 +1,60 @@
# NGINX Plus Proxy with tools build
# NGINX Plus Proxy with NGINX Agent
# NGINX webservers with ingress-demo pages
# NGINX Basics, Nov 2024
# NGINX One Console, Mar 2025
# Chris Akker, Shouvik Dutta, Adam Currier
#
services:
nginx-plus: # NGINX Plus Web / Load Balancer
hostname: nginx-plus
container_name: nginx-plus
image: nginx-plus:workshop # From Lab1
volumes: # Sync these folders to container
nginx-plus: # NGINX Plus Web / Load Balancer
environment:
NGINX_AGENT_SERVER_HOST: 'agent.connect.nginx.com'
NGINX_AGENT_SERVER_GRPCPORT: '443'
NGINX_AGENT_TLS_ENABLE: 'true'
NGINX_AGENT_SERVER_TOKEN: $TOKEN # Datakey From One Console
hostname: $NAME-nginx-plus
container_name: $NAME-nginx-plus
image: private-registry.nginx.com/nginx-plus/agent:nginx-plus-r32-debian # From Nginx Private Registry
volumes: # Sync these folders to container
- ./nginx-plus/etc/nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx-plus/etc/nginx/conf.d:/etc/nginx/conf.d
- ./nginx-plus/etc/nginx/includes:/etc/nginx/includes
- ./nginx-plus/usr/share/nginx/html:/usr/share/nginx/html
- ./nginx-plus/usr/share/nginx-plus-module-prometheus:/usr/share/nginx-plus-module-prometheus
ports:
- 80:80 # Open for HTTP
- 443:443 # Open for HTTPS
- 9000:9000 # Open for stub status page
- 9113:9113 # Open for Prometheus Scraper page
restart: always
- 9000:9000 # Open for API / Dashboard page
- 9113:9113 # Open for Prometheus scraper page
restart: always
#
web1:
hostname: web1
container_name: web1
hostname: $NAME-web1
container_name: $NAME-web1
image: nginxinc/ingress-demo # Image from Docker Hub
ports:
- "80" # Open for HTTP
- "443" # Open for HTTPS
web2:
hostname: web2
container_name: web2
hostname: $NAME-web2
container_name: $NAME-web2
image: nginxinc/ingress-demo
ports:
- "80"
- "433"
web3:
hostname: web3
container_name: web3
hostname: $NAME-web3
container_name: $NAME-web3
image: nginxinc/ingress-demo
ports:
- "80"
- "443"
- "443"
prometheus:
hostname: prometheus
container_name: prometheus
image: prom/prometheus
volumes:
- ./nginx-plus/etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
ports:
- "9090:9090"
- "9090:9090" # Prometheus Server Web Console
restart: always
depends_on:
- nginx-plus
Expand All @@ -58,7 +65,7 @@ services:
- grafana-storage:/var/lib/grafana
image: grafana/grafana
ports:
- "3000:3000"
- "3000:3000" # Grafana Server Web Console
restart: always
depends_on:
- nginx-plus
Expand Down
43 changes: 43 additions & 0 deletions labs/lab7/final/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# NGINX One Console, Mar 2025
# Chris Akker, Shouvik Dutta, Adam Currier
# nginx.conf
#
user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;

# Uncomment to enable NGINX Java Script Module
load_module modules/ngx_http_js_module.so; # Added for Prometheus

events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

include /etc/nginx/includes/log_formats/*.conf; # Custom Access logs formats found here

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

include /etc/nginx/conf.d/*.conf;

# Uncomment for Prometheus scraper page output
subrequest_output_buffer_size 32k; # Added for Prometheus

}
22 changes: 22 additions & 0 deletions labs/lab7/final/prometheus.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Nginx One Console
# NGINX Plus Prometheus configuration, for HTTP scraper page
# Chris Akker, Shouvik Dutta, Adam Currier, Mar 2025
# Based on: https://www.f5.com/company/blog/nginx/how-to-visualize-nginx-plus-with-prometheus-and-grafana
# prometheus.conf
#
# Uncomment all lines below
js_import /usr/share/nginx-plus-module-prometheus/prometheus.js;

server {

listen 9113; # This is the default port for Prometheus scraper page

location = /metrics {
js_content prometheus.metrics;
}

location /api {
api;
}

}
Binary file added labs/lab7/media/lab7_edit-nginx-conf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added labs/lab7/media/lab7_edit-prometheus-conf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added labs/lab7/media/lab7_prometheus-targets.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
38 changes: 38 additions & 0 deletions labs/lab7/nginx-plus/Dockerfile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# NginxPlus with Agent and NJS and Prometheus modules
# Nginx One Workshop - Internal F5
# Chris Akker, Shouvik Dutta, Adam Currier - Mar 2025
#
FROM private-registry.nginx.com/nginx-plus/agent:r32
COPY --from=private-registry.nginx.com/nginx-plus/modules:r32-prometheus-debian usr/ /usr/
#
#
# Install prerequisite packages:
RUN apt-get update && apt-get install -y apt-transport-https lsb-release ca-certificates curl wget gnupg2 net-tools vim tree openssl jq
#
# Download the apt configuration to `/etc/apt/apt.conf.d`:
RUN wget -P /etc/apt/apt.conf.d https://cs.nginx.com/static/files/90pkgs-nginx
#
# Copy certificate files and dhparams
# COPY etc/ssl /etc/ssl
#
# COPY /etc/nginx (Nginx configuration) directory
COPY etc/nginx /etc/nginx
RUN chown -R nginx:nginx /etc/nginx
# # Forward request logs to Docker log collector:
# && ln -sf /dev/stdout /var/log/nginx/access.log \
# && ln -sf /dev/stderr /var/log/nginx/error.log \
# Remove the cert/keys from the image
# && rm /etc/ssl/nginx/nginx-repo.crt /etc/ssl/nginx/nginx-repo.key
#
# COPY /usr/share/nginx/html (Nginx files) directory
COPY usr/share/nginx/html /usr/share/nginx/html
RUN chown -R nginx:nginx /usr/share/nginx/html
#
# COPY /etc/prometheus (Prometheus files) directory
COPY /etc/prometheus /etc/prometheus
RUN chown -R nginx:nginx /etc/prometheus
#
# EXPOSE ports, HTTP 80, HTTP 8080, HTTPS 443, Nginx API / status page 9000, Prometheus Exporter page 9113
EXPOSE 80 443 8080 9000 9113
STOPSIGNAL SIGTERM
CMD ["nginx", "-g", "daemon off;"]
2 changes: 1 addition & 1 deletion labs/lab7/nginx-plus/etc/nginx/conf.d/dashboard.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# NGINX Plus Basics, Nov 2024
# NGINX One Console, Nov 2024
# Chris Akker, Shouvik Dutta, Adam Currier
# dashboard.conf
#
Expand Down
2 changes: 1 addition & 1 deletion labs/lab7/nginx-plus/etc/nginx/conf.d/prometheus.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# NGINX Plus Prometheus configuration, for HTTP scraper page
# Chris Akker, Nov 2024
# Based on: https://www.f5.com/company/blog/nginx/how-to-visualize-nginx-plus-with-prometheus-and-grafana
# Nginx Basics
# Nginx One Console
#
# Uncomment all lines below
# js_import /usr/share/nginx-plus-module-prometheus/prometheus.js;
Expand Down
8 changes: 6 additions & 2 deletions labs/lab7/nginx-plus/etc/nginx/conf.d/status_ok.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# NGINX One Console, Nov 2024
# Chris Akker, Shouvik Dutta, Adam Currier
# status_ok.conf
# Simple health check expecting http 200 and correct Content-Type
#
match status_ok {
status 200;
header Content-Type = "text/html; charset=utf-8"; # For the nginx-cafe html
}
header Content-Type = "text/html; charset=utf-8"; # For the nginx-cafe html
}
2 changes: 1 addition & 1 deletion labs/lab7/nginx-plus/etc/nginx/conf.d/upstreams.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# NGINX Basics, Plus Proxy to three upstream NGINX containers
# Nov 2024 - Chris Akker, Shouvik Dutta, Adam Currier
# Chris Akker, Shouvik Dutta, Adam Currier - Mar 2025
# nginx_cafe servers
#
upstream nginx_cafe { # Upstream block, the name is "nginx_cafe"
Expand Down
2 changes: 1 addition & 1 deletion labs/lab7/nginx-plus/etc/nginx/includes/keepalive.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Default is HTTP/1, keepalive is only enabled in HTTP/1.1
# Nginx default to upstreams is HTTP/1.0, keepalive is only enabled in HTTP/1.1
proxy_http_version 1.1;

# Remove the Connection header if the client sends it,
Expand Down
2 changes: 1 addition & 1 deletion labs/lab7/nginx-plus/etc/nginx/includes/proxy_headers.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Set Headers to the proxied servers ##

# client address in a binary form, value’s length is always 4 bytes for IPv4 addresses or 16 bytes for IPv6 addresses
# client's IP address
proxy_set_header X-Real-IP $remote_addr;

# X-Forwarded-For client request header field with the $remote_addr variable appended to it,
Expand Down
6 changes: 5 additions & 1 deletion labs/lab7/nginx-plus/etc/prometheus/prometheus.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Prometheus config file
# Chris Akker, Shouvik Dutta, Adam Currier - Mar 2025
# prometheus.yml
#
global:
scrape_interval: 15s

Expand All @@ -10,4 +14,4 @@ scrape_configs:
scrape_interval: 5s

static_configs:
- targets: ['nginx-plus:9113'] # NGINX Plus container
- targets: ['nginx-plus:9113'] # NGINX Plus container
Loading
Loading