Apache2 Webserver Linux - Netzwerk und Serveradminstration

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen

Ziel des Projektes

  • Wir wollen einen Apache2 Webserver integrieren

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.11 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
Alternative
  • debian-setup.sh oder rocky-setup.sh

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>