apache基本身份validation可以在自定义SSL端口上正常工作

这是针对运行Apache 2.2的传统系统,由于各种原因,安全的Web服务器无法在端口443上运行(该端口被别的东西使用)。 所以它被configuration为在端口8443上运行,并且在非SSLconfiguration中有这一行,它将所有请求redirect到“pipe理”页面到安全连接:

RewriteRule ^/admin(.*)$ https://%{SERVER_NAME}:8443/admin [R=302,L] 

这工作正常 – 如果您尝试浏览到:

 http://server.com/admin 

您被正确地redirect到:

 https://server.com:8443/admin 

此时,会出现一个authentication表单login, AuthType设置为Digest 。 这似乎工作正常,但input一个有效的用户名和密码,浏览器被redirect到:

 https://server.com/admin ^^^^^ ^ 

注意丢失的端口号。 现在,如果你在浏览器中input正确的地址,

 https://server.com:8443/admin 

则会出现相同的apache身份validation表单,但是这次login后,端口号被保留,并显示pipe理页面。

所以,我的问题是,在不更改端口号的情况下,是否可以将非SSL页面redirect到SSL页面,以便validation保留端口号? 我在Auth Digest文档中找不到有关端口号的任何内容,但是我假设这是与来自浏览器请求或重写规则的原始URI有关的。

基本authentication可以在任何端口上完成。 基本身份validation也可以对特定资源进行身份validation,并且不涉及任何redirect:相反,它只是在密码对话框之后再次请求相同的URL,但是这次使用HTTP请求中的凭据。 由于基本身份validation没有涉及redirect,这意味着您看到的redirect不是由身份validation引起的,而是在您的configuration中的某处明确configuration的。

我创build了一个最小的testing用例,我认为这是答案。 请评论,如果不是这样,或者如果这只是一个可怕的黑客解决方法别的东西。

非SSL conf:

 <VirtualHost *:80> ServerName server.com RewriteEngine On RewriteRule ^/secret(.*)$ https://%{SERVER_NAME}:8443/secret [R=302,L] RewriteRule ^/public(.*)$ https://%{SERVER_NAME}:8443/public [R=302,L] </VirtualHost> 

SSL conf:

 LoadModule ssl_module modules/mod_ssl.so NameVirtualHost *:8443 Listen *:8443 <VirtualHost *:8443> ServerName server.com:8443 UseCanonicalName On SSLEngine on # SSL cert/key SSLCertificateFile /path/to/cert.crt SSLCertificateChainFile /path/to/cert.chain.crt SSLCertificateKeyFile /path/to/cert.key DocumentRoot "/var/www" <Directory "/var/www/public"> DirectoryIndex index.html index.php Options -Indexes FollowSymlinks Order allow,deny Allow from all </Directory> <Directory "/var/www/secret"> DirectoryIndex index.php index.html AuthName "Secret Pages" AuthType Digest AuthUserFile /etc/httpd/test-digests Require valid-user Options -Indexes FollowSymlinks AllowOverride None Order allow,deny Allow from localhost.localdomain Satisfy any </Directory> </VirtualHost> 

请注意SSLconfiguration中的ServerName行。 如果我没有将非标准端口放在那里,那么一旦input了用户名/密码,摘要redirect似乎使用标准https端口443,这导致我在原始问题中概述的行为。 一旦港口在那里,行为是按要求的。

因此,至less从这个angular度来看,如果SSL运行在非标准的端口上,并且使用Digest(或者我猜基本的)apacheauthentication,就必须在ServerNameconfiguration中指定端口。 这是我从文档中没有看到的东西。