Rocky www: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
| Zeile 51: | Zeile 51: | ||
= VirtualHost konfigurieren = | = 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 | * rm /etc/httpd/conf.d/ssl.conf | ||
* vi /etc/httpd/conf.d/www.conf | * vi /etc/httpd/conf.d/www.conf | ||
<pre> | <pre> | ||
Listen 443 https | Listen 443 https | ||
| + | |||
# HTTP → HTTPS Redirect | # HTTP → HTTPS Redirect | ||
<VirtualHost *:80> | <VirtualHost *:80> | ||
| Zeile 65: | Zeile 66: | ||
<VirtualHost *:443> | <VirtualHost *:443> | ||
ServerName www.it2XX.int | ServerName www.it2XX.int | ||
| − | DocumentRoot /var/www/ | + | DocumentRoot /var/www/html |
SSLEngine on | SSLEngine on | ||
SSLCertificateFile /etc/ssl/own.crt | SSLCertificateFile /etc/ssl/own.crt | ||
SSLCertificateKeyFile /etc/ssl/own.key | SSLCertificateKeyFile /etc/ssl/own.key | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
# PHP über FPM | # PHP über FPM | ||
| Zeile 85: | Zeile 81: | ||
</VirtualHost> | </VirtualHost> | ||
</pre> | </pre> | ||
| − | |||
| − | |||
| − | |||
| − | |||
= Beispielseite = | = Beispielseite = | ||
| − | ;Eine einfache PHP-Seite die den Hostnamen und die aktuelle Zeit anzeigt | + | ;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/ | + | * vi /var/www/html/index.php |
<pre> | <pre> | ||
<!DOCTYPE html> | <!DOCTYPE html> | ||
| Zeile 130: | Zeile 122: | ||
= SELinux = | = SELinux = | ||
| − | ;SELinux läuft auf Rocky standardmäßig im enforcing-Modus. | + | ;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 == | == Kontext setzen == | ||
| − | + | * semanage fcontext -a -t httpd_sys_content_t "/etc/ssl/own.*" | |
| − | + | * restorecon -Rv /etc/ssl/own.* | |
| − | |||
| − | |||
| − | *semanage fcontext -a -t httpd_sys_content_t "/etc/ssl/own.*" | ||
| − | *restorecon -Rv /etc/ssl/own.* | ||
;Kontext prüfen | ;Kontext prüfen | ||
| − | * ls - | + | * ls -Z /etc/ssl/own.crt /etc/ssl/own.key |
== Fehleranalyse == | == Fehleranalyse == | ||
Version vom 6. Juli 2026, 17:12 Uhr
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
Listen 443 https
# HTTP → HTTPS Redirect
<VirtualHost *:80>
ServerName www.it2XX.int
Redirect permanent / https://www.it2XX.int/
</VirtualHost>
# HTTPS VirtualHost
<VirtualHost *:443>
ServerName www.it2XX.int
DocumentRoot /var/www/html
SSLEngine on
SSLCertificateFile /etc/ssl/own.crt
SSLCertificateKeyFile /etc/ssl/own.key
# PHP über FPM
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"
</FilesMatch>
ErrorLog /var/log/httpd/www.it2XX.int_error.log
CustomLog /var/log/httpd/www.it2XX.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