🌐 Detecting your location…
📢 Advertisement — Configure AdSense in Appearance → Customize → AdSense Settings

Nginx Reverse Proxy Guide 2026: SSL, Lastausgleich und Produktionseinrichtung

⏱️3 min read  ·  453 words
Nginx Reverse Proxy Guide 2026: SSL, Load Balancing and Production Setup

Nginxist der am weitesten verbreitete Webserver und Reverse-Proxy im Jahr 2026. Er verarbeitet Millionen von Anfragen pro Sekunde, beendet SSL, verteilt die Last auf Backends und stellt statische Dateien mit Betriebssystemgeschwindigkeit bereit. Dieses Handbuch behandelt Nginx von der Installation bis zur Produktionskonfiguration mit SSL und Caching.

Installieren Sie Nginx

# Ubuntu/Debian
sudo apt install nginx
sudo systemctl enable nginx
sudo systemctl start nginx

# Check status
sudo nginx -t          # test config
sudo systemctl status nginx

# Config location
ls /etc/nginx/sites-available/

Grundlegender Reverse-Proxy

Leiten Sie den Datenverkehr von Port 80 an Ihre App weiter, die auf Port 8000 ausgeführt wird.

# /etc/nginx/sites-available/myapp
server {
    listen 80;
    server_name example.com www.example.com;

    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_set_header Host              $host;
        proxy_set_header X-Real-IP         $remote_addr;
        proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

# Enable site
sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx

SSL mit Let’s Encrypt (kostenlos)

# Install Certbot
sudo apt install certbot python3-certbot-nginx

# Obtain and install SSL
sudo certbot --nginx -d example.com -d www.example.com

# Auto-renewal (already added to cron by certbot)
sudo certbot renew --dry-run

Certbot ändert Ihre Nginx-Konfiguration automatisch, um HTTPS und eine HTTP-zu-HTTPS-Umleitung hinzuzufügen.

Vollständige Produktionskonfiguration mit SSL

# HTTP -> HTTPS redirect
server {
    listen 80;
    server_name example.com www.example.com;
    return 301 https://$host$request_uri;
}

# HTTPS server
server {
    listen 443 ssl http2;
    server_name example.com www.example.com;

    ssl_certificate     /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!MD5;

    # Security headers
    add_header X-Frame-Options DENY;
    add_header X-Content-Type-Options nosniff;
    add_header Strict-Transport-Security 'max-age=31536000' always;

    # Proxy to app
    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_set_header Host            $host;
        proxy_set_header X-Real-IP       $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_read_timeout 60s;
        proxy_connect_timeout 10s;
    }

    # Static files served directly by Nginx
    location /static/ {
        alias /var/www/myapp/static/;
        expires 1y;
        add_header Cache-Control 'public, immutable';
    }
}

Lastausgleich

upstream myapp_backend {
    least_conn;  # send to least busy server
    server 10.0.0.1:8000;
    server 10.0.0.2:8000;
    server 10.0.0.3:8000;
}

server {
    listen 443 ssl http2;
    location / {
        proxy_pass http://myapp_backend;
    }
}

Ratenbegrenzung

# In http block (nginx.conf)
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;

# In server block
location /api/ {
    limit_req zone=api burst=20 nodelay;
    proxy_pass http://127.0.0.1:8000;
}

Fazit

Nginx ist nicht ohne Grund der Produktionsstandard – schnell, stabil und flexibel. Verwenden Sie es als Reverse-Proxy vor jeder App (FastAPI, Django, Node, Rails). Fügen Sie Certbot für kostenloses SSL hinzu, konfigurieren Sie die Ratenbegrenzung und stellen Sie statische Dateien direkt bereit, um maximale Leistung zu erzielen.

✍️ Leave a Comment

Your email address will not be published. Required fields are marked *

🌐 Read in:🇬🇧 English🇩🇪 Deutsch🇧🇷 Português🇸🇦 العربية🇮🇳 हिन्दी🇧🇩 বাংলা