Installation
# Ubuntu/Debian
sudo apt update && sudo apt install nginx
# CentOS
sudo yum install nginx
Nginx Befehle
# Nginx starten
sudo systemctl start nginx
# Nginx stoppen
sudo systemctl stop nginx
# Nginx neustarten
sudo systemctl restart nginx
# Nginx neu laden (ohne Downtime)
sudo systemctl reload nginx
# Status von Nginx prüfen
sudo systemctl status nginx
# Nginx Konfigurationsdatei testen
sudo nginx -t
Wichtige Verzeichnisse
/etc/nginx/nginx.conf # Hauptkonfigurationsdatei
/etc/nginx/sites-available/ # Verfügbare Seiten
/etc/nginx/sites-enabled/ # Aktivierte Seiten
/var/log/nginx/access.log # Zugriff-Logs
/var/log/nginx/error.log # Fehler-Logs
Beispiel: Einfacher Reverse Proxy
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
Beispiel: Statische Webseite hosten
server {
listen 80;
server_name example.com;
root /var/www/html;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
SSL mit Let’s Encrypt (Certbot)
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com
Nginx Konfiguration neu laden
sudo systemctl reload nginx
Webroot Berechtigung und Owner:
sudo chown -R www-data /var/www/html/meine-beispielseite.ch
Ordner Berechtigung zuweisen
sudo chmod -R 755 /var/www/html/mein-beispielseite.ch
Files-Berechtigung zuweisen:
sudo chmod 644 /var/www/html/meine-beispielseite.ch/*