使用ssl访问流浪沙箱上的apache(端口转发)

Mar*_*ker 14 ssl virtualbox portforwarding vagrant

我已经构建了一个vagrant/virtualbox Web服务器作为开发沙箱,并在VM中为ssl配置了apache(在默认端口443上,带有自签名证书).我使用curl测试了VM本身的页面

curl -v -k https://mysite.mydomain.com/testSearch/results?postcode=WN8+0BA
Run Code Online (Sandbox Code Playgroud)

它看起来很开心,所以我很满意apache已经正确配置并在VM中工作.

但是,当我尝试通过https从主机的浏览器访问VM时,我无法这样做.

我已经添加

config.vm.forward_port "https", 443, 8443
Run Code Online (Sandbox Code Playgroud)

到我的vagrantfile,但试图访问该网址

https://mysite.mydomain.com:8443/testSearch/results?postcode=WN8+0BA
Run Code Online (Sandbox Code Playgroud)

根本无法显示我尝试过几种不同浏览器的页面:IE给出了一个毫无意义的"Internet Explorer无法显示网页"; Chrome给出了

SSL connection error
Unable to make a secure connection to the server. This may be a problem with the server or it may be requiring a client authentication certificate that you don't have.
Error 107 (net::ERR_SSL_PROTOCOL_ERROR): SSL protocol error.
Run Code Online (Sandbox Code Playgroud)

Firefox给了我

An error occurred during a connection to mysite.mydomain.com:8443.
SSL received a record that exceeded the maximum permissible length.
(Error code: ssl_error_rx_record_too_long)
Run Code Online (Sandbox Code Playgroud)

但即使是Firebug Net标签也没有告诉我任何更多信息.

我在VM apache上的访问或错误日志中没有得到任何内容,因此我怀疑vagrant根本没有转发ssl.

  • VM Guest OS:centos56x64
  • 主机:Windows 7 64位
  • JRuby:1.6.3(ruby-1.8.7-p330)(2011-07-07 965162f)(Java HotSpot(TM)64位服务器VM 1.6.0_24)[Windows 7-amd64-java]
  • 流浪汉:0.7.8
  • VirtualBox:4.0.12

我们将非常感激地接受任何援助.

小智 24

1)配置文件Vagrantfile

Vagrant::Config.run do |config|
    config.vm.box = "lucid32"
    config.vm.network "33.33.33.10"
    config.vm.forward_port "http", 80, 8080
end
Run Code Online (Sandbox Code Playgroud)

2)访问您的VM"lucid32"

vagrant ssh
Run Code Online (Sandbox Code Playgroud)

3)在VM中,配置Apache"虚拟主机":

<VirtualHost 33.33.33.10:80>
    ServerName        your-domain.dev
    DocumentRoot    /vagrant
    DirectoryIndex    index.php index.html index.htm

    <Directory /vagrant>
        AllowOverride All
        Allow from All
    </Directory>
</VirtualHost>

<VirtualHost 33.33.33.10:443>
    ServerName        your-domain.dev
    DocumentRoot    /vagrant
    DirectoryIndex    index.php index.html index.htm

    <Directory /vagrant>
        AllowOverride All
        Allow from All
    </Directory>

    SSLEngine on
    SSLCertificateFile /path/to/certicate/apache.pem
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

4)退出VM并在主机中配置文件"hosts":

33.33.33.10    your-domain.dev
Run Code Online (Sandbox Code Playgroud)

  • 使用此解决方案时,您必须在销毁Vagrant框时反复执行步骤2和3.使用配置(bash)脚本,Chef或Puppet将使此任务的重复性降低很多. (6认同)
  • 对于谷歌用户,我必须为“.crt”文件指定“SSLCertificateFile”,为“.key”文件指定“SSLCertificateKeyFile”。 (2认同)