Nginx Server Blocks (Virtual Hosts)
1. Document Root Directories
Verzeichnisse erstellen
- /var/www/domain1.de/html/
- /var/www/domain2.org/html/
Rechte vergeben
sudo chown -R $USER:$USER /var/www/domain1.de/html
sudo chown -R $USER:$USER /var/www/domain2.org/html
sudo chmod -R 755 /var/www
2. HTML-Dokumente erstellen
- /var/www/domain1.de/html/index.html
- /var/www/domain2.org/html/index.html
3. Für jede Domäne ein Server Block File erstellen
a) /etc/nginx/sites-available/domain1.de (default)
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/domain1.de/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
}
b) /etc/nginx/sites-available/domain2.org
server {
listen 80;
listen [::]:80;
root /var/www/domain2.org/html;
index index.html index.htm index.nginx-debian.html;
server_name domain2.org www.domain2.org;
location / {
try_files $uri $uri/ =404;
}
}
4. Server Blocks aktivieren
sudo ln -s /etc/nginx/sites-available/dimain1.de /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/domain2.org /etc/nginx/sites-enabled/
5. Bucket Size ändern in /etc/nginx/nginx.conf
http {
...
server_names_hash_bucket_size 64;
...
}
6. Konfiguration überprüfen und aktivieren
sudo nginx -t
sudo systemctl restart nginx