在将stream量转发到我的后端服务器之前,尝试使用基本身份validationconfiguration我的反向代理。 任何人都可以给我一个解决scheme。
示例:
用户(互联网) – >反向代理/虚拟主机服务器(需要在这里添加基本authentication) – >后端服务器(未authentication)
您可以按照此处的说明进行操作: 身份验证,授权和访问控制 。 你的反向代理的主要区别在于你要把auth的东西放在一个Location块中,即使这个文档说他们只允许在目录块中:
<Location /> AuthType Basic ... </Location>
在Location块之外,你可以放置你的代理命令,比如:
ProxyPass / http://localhost:8080/
这是我用来通过https完成对数据库的基本认证的配置。 我的后端服务器运行Tomcat,并使用AJP连接到它。 有趣的端口号(4443)是因为标准端口(443)已被使用,我不想在同一个端口上配置多个https服务。
<Ifmodulee mod_ssl.c> NameVirtualHost *:4443 <VirtualHost *:4443> serverAdmin webmaster@localhost 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> </Ifmodulee>
首先,检查你的apache2是否有utils包
sudo apt-get install apache2-utils
然后,设置用户名和密码。
sudo htpasswd -c /etc/apache2/.htpasswd <username>
之后,编辑您的反向代理以使用身份验证
<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>
至少,更新你的Apache
sudo service apache2 reload