Debian-basierte Systeme (z.B. Ubuntu):
sudo apt-get update
sudo apt-get install apache2Red Hat-basierte Systeme (z.B. CentOS):
sudo yum update
sudo yum install httpdDebian-basierte Systeme:
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod ssl
sudo systemctl restart apache2Red Hat-basierte Systeme: Bearbeiten der Apache-Konfigurationsdatei (httpd.conf), um die Module zu laden:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule ssl_module modules/mod_ssl.so
Danach Apache-Dienst neu starten:
sudo systemctl restart httpdBearbeiten der Datei
/etc/apache2/sites-available/000-default.conf (Debian) oder
/etc/httpd/conf/httpd.conf (Red Hat):
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# Proxy-Einstellungen
ProxyRequests On
ProxyVia On
<Proxy *>
Require all granted
</Proxy>
# Logging
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Bearbeiten der Datei
/etc/apache2/sites-available/default-ssl.conf (Debian) oder
/etc/httpd/conf.d/ssl.conf (Red Hat):
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# Proxy Konfiguration
ProxyRequests On
ProxyPass / http://backend_server/
ProxyPassReverse / http://backend_server/
# SSL Konfiguration
SSLEngine on
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
<Proxy *>
Require all granted
</Proxy>
# Logging
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
</IfModule>
Bearbeiten der Datei
/etc/apache2/sites-available/000-default.conf:
<Proxy "balancer://mycluster">
BalancerMember "http://backend1" loadfactor=1
BalancerMember "http://backend2" loadfactor=2
# Load Balancer Management
ProxySet lbmethod=byrequests
</Proxy>
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# Proxy Konfiguration
ProxyPass "/balancer" "balancer://mycluster"
ProxyPassReverse "/balancer" "balancer://mycluster"
# Logging
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Hinzufügen von Sicherheitsheadern zur Erhöhung der Sicherheit:
Header always set X-Content-Type-Options "nosniff"
Header always set X-Frame-Options "SAMEORIGIN"
Header always set X-XSS-Protection "1; mode=block"Erstellen einer eigenen Zertifizierungsstelle (CA)
openssl genpkey -algorithm RSA -out /etc/apache2/ssl/myCA.key -aes256
openssl req -new -x509 -days 3650 -key /etc/apache2/ssl/myCA.key -out /etc/apache2/ssl/myCA.pemErstellen eines privaten Schlüssels und eines Zertifikats für Apache
openssl genpkey -algorithm RSA -out /etc/apache2/ssl/apache.key
openssl req -new -key /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.csr
openssl x509 -req -days 3650 -in /etc/apache2/ssl/apache.csr -CA /etc/apache2/ssl/myCA.pem -CAkey /etc/apache2/ssl/myCA.key -CAcreateserial -out /etc/apache2/ssl/apache.crtAktivieren der notwendigen Module
sudo a2enmod ssl
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_connect
sudo systemctl restart apache2Bearbeiten der Apache-Konfigurationsdatei
sudo nano /etc/apache2/sites-available/000-default.confHinzufügen der folgenden Konfiguration für TLS-Interception
<VirtualHost *:3128>
SSLEngine on
SSLCertificateFile "/etc/apache2/ssl/apache.crt"
SSLCertificateKeyFile "/etc/apache2/ssl/apache.key"
SSLCACertificateFile "/etc/apache2/ssl/myCA.pem"
# Proxy-Konfiguration
ProxyRequests On
ProxyPreserveHost On
<Proxy *>
Require all granted
</Proxy>
# SSL/TLS-Interception
SSLProxyEngine On
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
ProxyPass / http://backendserver/
ProxyPassReverse / http://backendserver/
</VirtualHost>Initialisieren der SSL-Datenbank
sudo /usr/lib/apache2/security_file_certgen -c -s /var/lib/apache2/ssl_db -M 4MBsudo systemctl restart apache2/etc/apache2/ssl/myCA.pem auf die
Client-Geräte und installieren Sie es als vertrauenswürdige CA.update-ca-certificates für Debian-basierte Systeme).curl zum Testen des Proxiescurl -x http://<Apache-IP>:80 http://example.comDebian-basierte Systeme:
sudo tail -f /var/log/apache2/access.logRed Hat-basierte Systeme:
sudo tail -f /var/log/httpd/access_logDurch diese Schritte können Sie Apache effektiv als HTTP-Proxy einrichten und betreiben, sowohl als Forward Proxy für interne Netzwerke als auch als Reverse Proxy für Webanwendungen, um die Sicherheit, Leistung und Verfügbarkeit zu erhöhen.