Apache2 Webserver Linux - Netzwerk und Serveradminstration: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
(Die Seite wurde neu angelegt: „=Installation= Apache2 wird zusammen mit PHP und dem Apache-PHP-Modul installiert. *sudo apt install -y apache2 php libapache2-mod-php =PHP aktivieren= Das PH…“) |
|||
| (11 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
| Zeile 1: | Zeile 1: | ||
| + | ==Ziel des Projektes== | ||
| + | *Wir wollen einen Apache2 Webserver integrieren | ||
| + | *Wir wollen ihn gegen unseren LDAP Server authentifieren | ||
| + | *Ziel ist es sich mit den Benutzern die in der ldap sudo Gruppe per ssh einzulogen und dann zu administrieren | ||
| + | |||
| + | ==Vorab sind im Nameserver Einträge hinzuzufügen== | ||
| + | ===auf dem ns.2XX.int === | ||
| + | ;in der /var/cache/bind/it2XX.int | ||
| + | www IN A 10.88.213.9 | ||
| + | _ldap._tcp IN SRV 10 70 389 ldap | ||
| + | ;in der /var/cache/bind/2XX.88.10.in-addr.arpa | ||
| + | 9 IN PTR www.it213.int. | ||
| + | ;Restart | ||
| + | *systemctl restart named | ||
| + | ;Kontrolle | ||
| + | *dig -t axfr it213.int | ||
| + | *dig -t axfr 213.88.10.in-addr.arpa | ||
| + | |||
| + | =Klonen der Maschine= | ||
| + | == Vorbereitungen == | ||
| + | * VirtualBox Server-Vorlage klonen | ||
| + | * Der Host soll im ''DMZ''-Netzwerk liegen | ||
| + | * statische IP-Adresse nach dem Netzwerkplan setzen (''/etc/network/interfaces'') | ||
| + | * SSH-Schlüssel des Kit Hosts für User ''kit'' hinterlegen | ||
| + | === Netzkonfiguration DNS-Server (DMZ) === | ||
| + | |||
| + | {| class="wikitable" style="background-color: #f2f2f2;" | ||
| + | ! Parameter !! Wert !! Erläuterung | ||
| + | |- | ||
| + | | '''Netzwerk (NIC)''' || DMZ || Interface-Zuweisung in VirtualBox | ||
| + | |- | ||
| + | | '''IP''' || 10.88.2XX.9 || Statische IP | ||
| + | |- | ||
| + | | '''CIDR''' || 24 || Classless Inter-Domain Routing Präfixlänge | ||
| + | |- | ||
| + | | '''GW''' || 10.88.2XX.1 || GATEWAY | ||
| + | |- | ||
| + | | '''NS''' || 10.88.2XX.21 || Resolver | ||
| + | |- | ||
| + | | '''FQDN''' || www.it2XX.int || Fully Qualified Domain Name | ||
| + | |- | ||
| + | | '''SHORT''' || www || Short Name | ||
| + | |- | ||
| + | | '''DOM''' || it2XX.int|| Domain Name | ||
| + | |} | ||
| + | ;Anpassen des Templates | ||
| + | *[[Anpassen des Debian Templates]] | ||
| + | |||
| + | |||
| + | =Integration in LDAP= | ||
| + | *[[Client-Anbindung via DNS Service Discovery]] | ||
=Installation= | =Installation= | ||
Apache2 wird zusammen mit PHP und dem Apache-PHP-Modul installiert. | Apache2 wird zusammen mit PHP und dem Apache-PHP-Modul installiert. | ||
| Zeile 5: | Zeile 56: | ||
=PHP aktivieren= | =PHP aktivieren= | ||
Das PHP-Modul wird aktiviert und Apache neu geladen. | Das PHP-Modul wird aktiviert und Apache neu geladen. | ||
| − | *a2enmod php8. | + | *a2enmod php8.4 |
*systemctl reload apache2 | *systemctl reload apache2 | ||
| Zeile 49: | Zeile 100: | ||
=Testen= | =Testen= | ||
Im Browser die IP-Adresse des Servers aufrufen. | Im Browser die IP-Adresse des Servers aufrufen. | ||
| − | *http:// | + | *http://www.it2XX.int |
| + | =Handling= | ||
| + | *systemctl start apache2 | ||
| + | *systemctl stop apache2 | ||
| + | *systemctl restart apache2 | ||
| + | *systemctl reload apache2 | ||
| + | *systemctl enable apache2 | ||
| + | *systemctl disable apache2 | ||
| + | *systemctl status apache2 | ||
| + | *journalctl -fu apache2 | ||
| + | *journalctl -xu apache2 | ||
| + | *tail -f /var/log/apache2/access.log | ||
| + | =Konfiguration der Seiten= | ||
| + | ;Verfügbare Konfigurationen | ||
| + | *DIR: /etc/apache2/sites-available/ | ||
| + | ;Aktivierten Konfigurationen | ||
| + | /etc/apache2/sites-enabled | ||
| + | =Aktivieren und deaktivieren= | ||
| + | ;AKTIVIERT | ||
| + | *a2ensite 000-default.conf | ||
| + | ;DEAKTIVIERT | ||
| + | *a2dissite 000-default.conf | ||
| + | =Default Seite= | ||
| + | *cat /etc/apache2/sites-enabled/000-default.conf | ||
| + | <pre> | ||
| + | <VirtualHost *:80> | ||
| + | # The ServerName directive sets the request scheme, hostname and port that | ||
| + | # the server uses to identify itself. This is used when creating | ||
| + | # redirection URLs. In the context of virtual hosts, the ServerName | ||
| + | # specifies what hostname must appear in the request's Host: header to | ||
| + | # match this virtual host. For the default virtual host (this file) this | ||
| + | # value is not decisive as it is used as a last resort host regardless. | ||
| + | # However, you must set it for any further virtual host explicitly. | ||
| + | #ServerName www.example.com | ||
| + | |||
| + | ServerAdmin webmaster@localhost | ||
| + | DocumentRoot /var/www/html | ||
| + | |||
| + | # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, | ||
| + | # error, crit, alert, emerg. | ||
| + | # It is also possible to configure the loglevel for particular | ||
| + | # modules, e.g. | ||
| + | #LogLevel info ssl:warn | ||
| + | |||
| + | ErrorLog ${APACHE_LOG_DIR}/error.log | ||
| + | CustomLog ${APACHE_LOG_DIR}/access.log combined | ||
| + | |||
| + | # For most configuration files from conf-available/, which are | ||
| + | # enabled or disabled at a global level, it is possible to | ||
| + | # include a line for only one particular virtual host. For example the | ||
| + | # following line enables the CGI configuration for this host only | ||
| + | # after it has been globally disabled with "a2disconf". | ||
| + | #Include conf-available/serve-cgi-bin.conf | ||
| + | </VirtualHost> | ||
| + | </pre> | ||
Aktuelle Version vom 24. April 2026, 09:13 Uhr
Ziel des Projektes
- Wir wollen einen Apache2 Webserver integrieren
- Wir wollen ihn gegen unseren LDAP Server authentifieren
- Ziel ist es sich mit den Benutzern die in der ldap sudo Gruppe per ssh einzulogen und dann zu administrieren
Vorab sind im Nameserver Einträge hinzuzufügen
auf dem ns.2XX.int
- in der /var/cache/bind/it2XX.int
www IN A 10.88.213.9 _ldap._tcp IN SRV 10 70 389 ldap
- in der /var/cache/bind/2XX.88.10.in-addr.arpa
9 IN PTR www.it213.int.
- Restart
- systemctl restart named
- Kontrolle
- dig -t axfr it213.int
- dig -t axfr 213.88.10.in-addr.arpa
Klonen der Maschine
Vorbereitungen
- VirtualBox Server-Vorlage klonen
- Der Host soll im DMZ-Netzwerk liegen
- statische IP-Adresse nach dem Netzwerkplan setzen (/etc/network/interfaces)
- SSH-Schlüssel des Kit Hosts für User kit hinterlegen
Netzkonfiguration DNS-Server (DMZ)
| Parameter | Wert | Erläuterung |
|---|---|---|
| Netzwerk (NIC) | DMZ | Interface-Zuweisung in VirtualBox |
| IP | 10.88.2XX.9 | Statische IP |
| CIDR | 24 | Classless Inter-Domain Routing Präfixlänge |
| GW | 10.88.2XX.1 | GATEWAY |
| NS | 10.88.2XX.21 | Resolver |
| FQDN | www.it2XX.int | Fully Qualified Domain Name |
| SHORT | www | Short Name |
| DOM | it2XX.int | Domain Name |
- Anpassen des Templates
Integration in LDAP
Installation
Apache2 wird zusammen mit PHP und dem Apache-PHP-Modul installiert.
- sudo apt install -y apache2 php libapache2-mod-php
PHP aktivieren
Das PHP-Modul wird aktiviert und Apache neu geladen.
- a2enmod php8.4
- systemctl reload apache2
Webroot
Das Webroot-Verzeichnis ist der Standardort für Webseiten unter Apache.
- ls /var/www/html
Dynamische Testseite erstellen
Die Datei index.php ersetzt die Apache-Standardseite und gibt Systeminformationen aus.
- sudo nano /var/www/html/index.php
Inhalt der Datei:
<?php
$hostname = gethostname();
$ip = $_SERVER['SERVER_ADDR'];
$domain = php_uname('n');
// Gateway und Nameserver aus /etc/resolv.conf und ip route auslesen
$nameserver = shell_exec("awk '/^nameserver/{print $2; exit}' /etc/resolv.conf");
$gateway = shell_exec("ip route | awk '/^default/{print $3; exit}'");
?>
<!DOCTYPE html>
<html>
<head><title>Systeminfo</title></head>
<body>
<h1>Systeminfo</h1>
<table>
<tr><td>Hostname</td><td><?= htmlspecialchars($hostname) ?></td></tr>
<tr><td>IP-Adresse</td><td><?= htmlspecialchars($ip) ?></td></tr>
<tr><td>Domain</td><td><?= htmlspecialchars($domain) ?></td></tr>
<tr><td>Nameserver</td><td><?= htmlspecialchars(trim($nameserver)) ?></td></tr>
<tr><td>Gateway</td><td><?= htmlspecialchars(trim($gateway)) ?></td></tr>
</table>
</body>
</html>
Standardseite deaktivieren
Die Apache-Standardseite wird deaktiviert damit die neue PHP-Seite aufgerufen wird.
- sudo rm /var/www/html/index.html
Testen
Im Browser die IP-Adresse des Servers aufrufen.
Handling
- systemctl start apache2
- systemctl stop apache2
- systemctl restart apache2
- systemctl reload apache2
- systemctl enable apache2
- systemctl disable apache2
- systemctl status apache2
- journalctl -fu apache2
- journalctl -xu apache2
- tail -f /var/log/apache2/access.log
Konfiguration der Seiten
- Verfügbare Konfigurationen
- DIR: /etc/apache2/sites-available/
- Aktivierten Konfigurationen
/etc/apache2/sites-enabled
Aktivieren und deaktivieren
- AKTIVIERT
- a2ensite 000-default.conf
- DEAKTIVIERT
- a2dissite 000-default.conf
Default Seite
- cat /etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>