<VirtualHost *:82> SSLEngine on SSLCertificateFile /etc/ssl/certs/cert.pem DocumentRoot "/var/www/site" <Directory "/var/www/site"> allow from all Options -Indexes </Directory> </VirtualHost>
这是我的虚拟主机configuration。 它在端口82上工作。
我的问题是,当我试图得到这个页面与http返回错误页面,如:
Bad Request Your browser sent a request that this server could not understand. Reason: You're speaking plain HTTP to an SSL-enabled server port. Instead use the HTTPS scheme to access this URL, please. Hint: https://localhost:82/
所以,我只是想redirectHTTP到端口82上的https。我尝试添加:
RewriteEngine on RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
但它不工作,因为它首先需要http。
我怎样才能做到这一点?
谢谢。
我知道你可以redirect80到443 ssl,那些是不同的端口。 但在我的情况下,我想通过ssl在这个端口(82)服务的一切。 也许有可能做到这一点,自定义错误页面,因为它显示一个错误页面,当我在这个端口上使用http,但我不知道如何
您不能在同一个端口上同时encryptionencryption和纯文本。 如果有人连接到纯文本端口说端口80或81,那么你可以转发他们到你的HTTPS端口说82在这个例子中。 所以这样的事情应该做的伎俩:
# Plain-text rewrite: <VirtualHost *:81> DocumentRoot "/var/www/site" RewriteEngine on RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}:82%{REQUEST_URI} <Directory "/var/www/site"> allow from all Options -Indexes </Directory> </VirtualHost> # SSL config <VirtualHost *:82> SSLEngine on SSLCertificateFile /etc/ssl/certs/cert.pem DocumentRoot "/var/www/site" <Directory "/var/www/site"> allow from all Options -Indexes </Directory> </VirtualHost>
在这种情况下,任何连接到端口81的用户都将被转发到端口82.任何连接到端口82的用户都将通过SSL。