🌐
Networking & Server

Nginx

High-performance web server and reverse proxy

🐧 Linux🍎 Mac🪟 Windows📋 Quick reference →
Reviewed: Tested on: Kubernetes 1.29 · Terraform 1.8 · Ubuntu 22.04

If you're on Kubernetes 1.27 or older

  • Ingress: networking.k8s.io/v1 is required — v1beta1 removed in 1.22+
  • Pod Security: PodSecurityPolicy removed in 1.25 — use Pod Security Admission (PSA) labels
  • HPA v2 autoscaling/v2 is stable — check API version in manifests

If you're on Kubernetes 1.28

  • Sidecar containers (1.29+) change init-container ordering — review sidecar docs before upgrade
  • Verify metrics-server and HPA after control plane bump

Ingress-NGINX + older clusters

  • ingressClassName replaces deprecated kubernetes.io/ingress.class annotation
  • Verify admission webhooks after controller upgrade

What is this?

Nginx serves websites to visitors and can also balance traffic across multiple backend servers.

📁

Config files for Nginx

Where to create or edit the main configuration — paths below match the setup steps.

  • /etc/nginx/nginx.conf

    Location: Linux — main config

    Global nginx settings and includes

  • /etc/nginx/sites-available/*

    Location: Debian/Ubuntu vhosts

    Virtual hosts and reverse proxy rules

📥

Step 01

Install Nginx

(01)Install

Linux
1sudo apt-get update && sudo apt-get install -y nginx
2sudo systemctl enable nginx && sudo systemctl start nginx
⚙️

Step 02

Configure Nginx

(01)Virtual host + reverse proxy

Linux
1sudo nano /etc/nginx/sites-available/myapp
2# server {
3# listen 80;
4# server_name example.com;
5# location / { proxy_pass http://127.0.0.1:3000; }
6# }
7sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/
8sudo nginx -t && sudo systemctl reload nginx

Step 03

Verify

(01)Test

Linux
1curl -I http://localhost

Step 04

Manage

(01)Reload

Linux
1sudo nginx -t && sudo systemctl reload nginx
🔧

Step 05

Common Problems

#1502 Bad Gateway

Linux
1# Check nginx error log
2sudo tail -f /var/log/nginx/error.log
3# Verify backend is running
4curl http://localhost:3000
5sudo nginx -t && sudo systemctl reload nginx

📋Config templates

3 YAML templates for Nginx. Copy and deploy after setup.

3 ready-to-copy templates. Expand one, copy the YAML, then run the deploy commands.

Ingress.yml

yaml
1apiVersion: networking.k8s.io/v1
2kind: Ingress
3metadata:
4 name: minimal-ingress
5 annotations:
6 nginx.ingress.kubernetes.io/rewrite-target: /
7spec:
8 rules:
9 - http:
10 paths:
11 - path: /testpath
12 pathType: Prefix
13 backend:
14 service:
15 name: test
16 port:
17 number: 80
📄

Step 01

Deploy Ingress

(01)Install NGINX Ingress Controller

Linux
1kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.11.1/deploy/static/provider/cloud/deploy.yaml
2kubectl wait --namespace ingress-nginx --for=condition=ready pod --selector=app.kubernetes.io/component=controller --timeout=120s

(02)Apply Ingress resource

Linux
1kubectl apply -f Ingress.yml
2kubectl get ingress
3kubectl describe ingress minimal-ingress