Rocky www

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen

Installation

DATEN

Parameter Wert Erläuterung
VM Name www Name der VM
Disk 20GB Vorgabe übernehmen
CPU 4 Cores Kerne
Ram 4 GB Speicher
Netzwerk (NIC) DMZ Interface-Zuweisung in VirtualBox
Admin root Passwort: radler
User kit Passwort: kit
IP 10.88.2XX.11/24 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
DOM it2XX.int Domain Name

Hostname

  • hostnamectl set-hostname FQDN

Netzwerk

  • nmcli con mod enp0s3 ipv4.addresses IP/CIDR
  • nmcli con mod enp0s3 ipv4.gateway GW
  • nmcli con mod enp0s3 ipv4.dns NS
  • nmcli con mod enp0s3 ipv4.method manual
  • nmcli con mod enp0s3 ipv4.dns-search DOM
  • nmcli con mod enp0s3 connection.autoconnect yes
  • nmcli con up enp0s3

Hintergrund

Die Verbindungen findet ihr hier
  • DIR: /etc/NetworkManager/system-connections/
In unserem Fall
  • cat /etc/NetworkManager/system-connections/enp0s3.nmconnection
[connection]
id=enp0s3
uuid=40ff96e5-0c0d-31de-9bf0-f75da265425b
type=ethernet
autoconnect-priority=-999
interface-name=enp0s3
timestamp=1784278716

[ethernet]

[ipv4]
address1=192.168.3.127/24
dns=192.168.20.1;
dns-search=it.int;
gateway=192.168.3.254
method=manual

[ipv6]
addr-gen-mode=eui64
method=auto

[proxy]

Apache Webserver auf Rocky Linux

Der Webserver läuft in der DMZ und stellt Webinhalte über HTTP und HTTPS bereit. HTTP-Anfragen werden automatisch auf HTTPS umgeleitet. Das Zertifikat kommt von web.samogo.de und liegt unter /etc/ssl/.

Installation

  • dnf install -y httpd mod_ssl

Zertifikat holen

  • get-cert.sh

PHP installieren

PHP wird über das dnf-Modul installiert – so lässt sich später auch eine andere Version aktivieren
  • dnf install -y php php-fpm php-mysqlnd php-json php-mbstring
PHP-FPM starten – httpd übergibt PHP-Anfragen an diesen Prozess
  • systemctl enable --now php-fpm

VirtualHost konfigurieren

Die mitgelieferte ssl.conf entfernen – sie bringt einen eigenen Dummy-VirtualHost auf *
443 mit, der mit unserem kollidiert. Dadurch fehlt aber auch "Listen 443", das normalerweise aus dieser Datei kommt – wir tragen es deshalb selbst ein
  • rm /etc/httpd/conf.d/ssl.conf
  • vi /etc/httpd/conf.d/www.conf
# HTTPS VirtualHost
<VirtualHost *:443>
    ServerName www.it213.int
    DocumentRoot /var/www/html

    SSLEngine on
    SSLCertificateFile    /etc/ssl/own.crt
    SSLCertificateKeyFile /etc/ssl/own.key

    <Directory /var/www/html>
        Options +Indexes
        AllowOverride None
        Require all granted
    </Directory>

    # PHP über FPM
    <FilesMatch \.php$>
        SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"
    </FilesMatch>

    ErrorLog  /var/log/httpd/www.it213.int_error.log
    CustomLog /var/log/httpd/www.it213.int_access.log combined
</VirtualHost>

Beispielseite

Eine einfache PHP-Seite die den Hostnamen und die aktuelle Zeit anzeigt. /var/www/html ist die Standard-DocumentRoot von httpd – existiert bereits, kein eigenes Verzeichnis und kein eigener SELinux-Kontext nötig
  • vi /var/www/html/index.php
<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="UTF-8">
    <title>Willkommen auf <?= gethostname() ?></title>
    <style>
        body { font-family: sans-serif; max-width: 600px; margin: 4em auto; }
        h1   { color: #c0392b; }
        p    { color: #333; }
    </style>
</head>
<body>
    <h1>Willkommen auf <?= gethostname() ?></h1>
    <p>Server: <strong><?= $_SERVER['SERVER_NAME'] ?></strong></p>
    <p>Zeit:   <strong><?= date('d.m.Y H:i:s') ?></strong></p>
    <p>PHP:    <strong><?= phpversion() ?></strong></p>
</body>
</html>

Konfiguration prüfen

Syntaxfehler erkennen bevor httpd neu gestartet wird
  • apachectl configtest
Syntax OK

Dienst starten

  • systemctl enable --now httpd
  • systemctl restart httpd

Firewall

HTTP und HTTPS auf dem www-Server freigeben
  • firewall-cmd --permanent --zone=public --add-service=http
  • firewall-cmd --permanent --zone=public --add-service=https
  • firewall-cmd --reload

SELinux

SELinux läuft auf Rocky standardmäßig im enforcing-Modus. /var/www/html ist bereits korrekt mit httpd_sys_content_t gelabelt – nur die Zertifikate unter /etc/ssl brauchen einen eigenen Kontext

Kontext setzen

  • semanage fcontext -a -t httpd_sys_content_t "/etc/ssl/own.*"
  • restorecon -Rv /etc/ssl/own.*
Kontext prüfen
  • ls -Z /etc/ssl/own.crt /etc/ssl/own.key

Fehleranalyse

Falls der Zugriff trotzdem fehlschlägt – SELinux-Blockaden anzeigen
  • ausearch -m avc -ts recent

Logs

  • journalctl -fu httpd
  • tail -f /var/log/httpd/www.it2XX.int_error.log
  • tail -f /var/log/httpd/www.it2XX.int_access.log

Test

Im Browser aufrufen – HTTP muss automatisch auf HTTPS umleiten
http://www.it2XX.int
https://www.it2XX.int
Zertifikat prüfen
  • openssl s_client -connect www.it2XX.int:443 -showcerts