Ich habe versucht, meinen Reverse-Proxy mit der Basisauthentifizierung zu konfigurieren, bevor der Datenverkehr an meinen Back-End-Server weitergeleitet wird. Kann mir jemand eine Lösung geben.
Beispiel hier:
Benutzer (Internet) -> Reverse Proxy/Vhosts-Server (hier muss eine Basisauthentifizierung hinzugefügt werden) -> Back-End-Server (nicht authentifiziert)
Sie können den Anweisungen hier folgen: Authentifizierung, Autorisierung und Zugriffskontrolle . Der Hauptunterschied für Ihren Reverse-Proxy besteht darin, dass Sie das Auth-Zeug in einem Location-Block ablegen möchten, obwohl in den Dokumenten angegeben ist, dass es nur in Directory-Blöcken zulässig ist:
<Location />
AuthType Basic
...
</Location>
Außerhalb des Location-Blocks können Sie Ihre Proxy-Befehle einfügen, z. B .:
ProxyPass / http://localhost:8080/
Hier ist die Konfiguration, mit der ich die Basisauthentifizierung über https für eine Datenbank durchgeführt habe. Auf meinem Back-End-Server läuft Tomcat und ich verbinde mich mit AJP. Die lustige Portnummer (4443) ist, weil der Standardport (443) bereits verwendet wurde und ich nicht mehrere https-Dienste auf demselben Port konfigurieren wollte.
<IfModule mod_ssl.c>
NameVirtualHost *:4443
<VirtualHost *:4443>
ServerAdmin [email protected]
ServerName ws.myserver.se
ServerAlias ws.myserveralias.se
ErrorLog /var/log/Apache2/ajpProxy.error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel info
CustomLog /var/log/Apache2/ajpProxy.log combined
DBDriver mysql
DBDParams "Host=127.0.0.1 port=3306 user=proxyAuthUser pass=yourDbPasswordHere dbname=yourDbName"
DBDMin 4
DBDKeep 8
DBDMax 20
DBDExptime 300
<Proxy *>
# core authentication and mod_auth_basic configuration
# for mod_authn_dbd
AuthType Basic
AuthName "Backend auth name"
AuthBasicProvider dbd
# core authorization configuration
Require valid-user
# mod_authn_dbd SQL query to authenticate a user
AuthDBDUserPWQuery \
"SELECT password FROM user WHERE emailAddress = %s"
AddDefaultCharset Off
Order deny,allow
Allow from all
</Proxy>
ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/
# SSL Engine Switch:
# Enable/Disable SSL for this virtual Host.
SSLEngine on
# A self-signed (snakeoil) certificate can be created by installing
# the ssl-cert package. See
# /usr/share/doc/Apache2.2-common/README.Debian.gz for more info.
# If both key and certificate are stored in the same file, only the
# SSLCertificateFile directive is needed.
SSLCertificateFile /etc/Apache2/ssl/yourCertificateFile.crt
SSLCertificateKeyFile /etc/Apache2/ssl/yourPrivateKeyFile.key
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
BrowserMatch "MSIE [2-6]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
# MSIE 7 and newer should be able to use keepalive
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
</VirtualHost>
</IfModule>
Überprüfen Sie zunächst, ob Ihr Apache2 das Paket utils enthält
Sudo apt-get install Apache2-utils
Stellen Sie dann den Benutzernamen und das Passwort ein.
Sudo htpasswd -c /etc/Apache2/.htpasswd <username>
Bearbeiten Sie anschließend Ihren Reverse-Proxy, um die Authentifizierung zu verwenden
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://someaddress:1234/
ProxyPassReverse / http://someaddress:1234/
Timeout 5400
ProxyTimeout 5400
ServerName dev.mydomain.com
ServerAlias *.dev.mydomain.com
<Proxy *>
Order deny,allow
Allow from all
Authtype Basic
Authname "Password Required"
AuthUserFile /etc/Apache2/.htpasswd
Require valid-user
</Proxy>
</virtualhost>
Zumindest aktualisieren Sie Ihren Apache
Sudo service Apache2 reload