Incus Apache

Webserver in Containern.

Container erstellen

incus launch ubuntu:22.04 webserver

Container konfigurieren

incus exec webserver -- bash

System aktualisieren

apt update && apt upgrade -y

Apache installieren

apt install apache2 php php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip

Netzwerk-Konfiguration

Port-Forwarding

# HTTP (80)
incus config device add webserver http80 proxy listen=tcp:0.0.0.0:80 connect=tcp:127.0.0.1:80

# HTTPS (443)
incus config device add webserver https443 proxy listen=tcp:0.0.0.0:443 connect=tcp:127.0.0.1:443

Apache-Konfiguration

nano /etc/apache2/sites-available/example.com.conf
<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com

    <Directory /var/www/example.com>
        Options -Indexes +FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/example.com_error.log
    CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined
</VirtualHost>

Site aktivieren

a2ensite example.com.conf
a2dissite 000-default.conf
systemctl reload apache2

PHP-Konfiguration

nano /etc/php/8.1/apache2/php.ini
memory_limit = 256M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 300

SSL-Konfiguration

# Zertifikate von Host kopieren
incus file push /etc/letsencrypt/live/example.com/fullchain.pem webserver/etc/ssl/certs/
incus file push /etc/letsencrypt/live/example.com/privkey.pem webserver/etc/ssl/private/

SSL VirtualHost

<VirtualHost *:443>
    ServerName example.com
    DocumentRoot /var/www/example.com

    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/fullchain.pem
    SSLCertificateKeyFile /etc/ssl/private/privkey.pem

    <Directory /var/www/example.com>
        Options -Indexes +FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Module aktivieren

a2enmod rewrite
a2enmod ssl
a2enmod headers
systemctl restart apache2

Test

# Von Host aus testen
curl -I http://localhost
curl -I https://localhost

Zurück zur Container-Übersicht