Apache2 Workshop VirtualHosts: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
| Zeile 43: | Zeile 43: | ||
*Die Konfigurationsdatei sollte man unter '''/etc/apache2/sites-available''' ablegen. | *Die Konfigurationsdatei sollte man unter '''/etc/apache2/sites-available''' ablegen. | ||
*Danach wird sie mit a2ensite '''Dateiname''' aktiviert. | *Danach wird sie mit a2ensite '''Dateiname''' aktiviert. | ||
| − | ==Zuerst erstellen wie ein Verzeichnis und eine Webseite= | + | ==Zuerst erstellen wie ein Verzeichnis und eine Webseite== |
*mkdir /var/www/porty | *mkdir /var/www/porty | ||
cat<<HERE > /var/www/porty/index.html | cat<<HERE > /var/www/porty/index.html | ||
<pre> | <pre> | ||
| + | <!DOCTYPE html> | ||
| + | <html lang="de"> | ||
| + | <head> | ||
| + | <meta charset="UTF-8"> | ||
| + | <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| + | <title>Willkommen bei Porty</title> | ||
| + | <style> | ||
| + | body { | ||
| + | font-family: Arial, sans-serif; | ||
| + | text-align: center; | ||
| + | margin: 50px; | ||
| + | background-color: #f4f4f4; | ||
| + | } | ||
| + | .container { | ||
| + | background: white; | ||
| + | padding: 20px; | ||
| + | border-radius: 10px; | ||
| + | box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1); | ||
| + | display: inline-block; | ||
| + | } | ||
| + | h1 { | ||
| + | color: #0073e6; | ||
| + | } | ||
| + | p { | ||
| + | color: #333; | ||
| + | } | ||
| + | </style> | ||
| + | </head> | ||
| + | <body> | ||
| + | <div class="container"> | ||
| + | <h1>Willkommen auf Porty!</h1> | ||
| + | <p>Schön, dass du da bist. Dies ist eine kleine Testseite für die Domain porty.</p> | ||
| + | <p>Viel Spaß beim Erkunden!</p> | ||
| + | </div> | ||
| + | </body> | ||
| + | </html> | ||
HERE | HERE | ||
Version vom 14. März 2025, 17:43 Uhr
Grundlagen
- Apache unterstützt VirtualHosts, um mehrere Webseiten auf einer Maschine zu hosten.
- Es gibt zwei Arten: Named-based (mehrere Domains auf einer IP) und IP-based (jede Seite hat eine eigene IP).
- Die Konfigurationsdateien für VirtualHosts liegen in /etc/apache2/sites-available/.
- Aktivierte VirtualHosts werden als Symlink in /etc/apache2/sites-enabled/ hinterlegt.
- Ein VirtualHost wird mit a2ensite meine-seite.conf aktiviert.
- Ein VirtualHost wird mit a2dissite meine-seite.conf deaktiviert.
- Nach Änderungen muss Apache neu geladen werden: systemctl reload apache2.
/etc/apache2/sites-available/000-default.conf
Zweck
- Diese Datei definiert einen Standard-VirtualHost für HTTP-Anfragen.
- Sie wird von Apache verwendet, wenn keine andere Konfiguration passt.
- Standardmäßig lauscht dieser VirtualHost auf Port 80.
- Die Datei kann als Vorlage für weitere VirtualHosts genutzt werden.
- Änderungen an dieser Datei erfordern einen Neustart oder Reload von Apache.
Inhalt
- cat /etc/apache2/sites-available/000-default.conf
# Standard-VirtualHost für HTTP (Port 80)
<VirtualHost *:80>
# Hauptdomain des VirtualHosts
ServerName www.example.com
# E-Mail-Adresse des Administrators (wird in Fehlerseiten angezeigt)
ServerAdmin webmaster@localhost
# Wurzelverzeichnis der Webseite
DocumentRoot /var/www/html
# Fehlerprotokoll für diesen VirtualHost
ErrorLog ${APACHE_LOG_DIR}/error.log
# Zugriffprotokoll mit vordefiniertem Log-Format
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Weitere Domain anlegen
- Die Konfigurationsdatei sollte man unter /etc/apache2/sites-available ablegen.
- Danach wird sie mit a2ensite Dateiname aktiviert.
Zuerst erstellen wie ein Verzeichnis und eine Webseite
- mkdir /var/www/porty
cat<<HERE > /var/www/porty/index.html
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Willkommen bei Porty</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 50px;
background-color: #f4f4f4;
}
.container {
background: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
display: inline-block;
}
h1 {
color: #0073e6;
}
p {
color: #333;
}
</style>
</head>
<body>
<div class="container">
<h1>Willkommen auf Porty!</h1>
<p>Schön, dass du da bist. Dies ist eine kleine Testseite für die Domain porty.</p>
<p>Viel Spaß beim Erkunden!</p>
</div>
</body>
</html>
HERE
Datei
- cat /etc/apache2/sites-available/02-porty.conf
<VirtualHost *:80>
ServerName porty.it113.int
ServerAdmin technik@it113.int
DocumentRoot /var/www/porty
ErrorLog ${APACHE_LOG_DIR}/porty-error.log
CustomLog ${APACHE_LOG_DIR}/porty-access.log combined
</VirtualHost>