2011-08-12 177 views
13

我已经建立了一个流浪汉/ VirtualBox虚拟Web服务器作为开发沙盒,并在虚拟机配置了Apache的SSL(默认端口443上颠沛流离的沙箱访问Apache的,具有自签名证书)。我已经使用curl使用SSL(端口转发)

curl -v -k https://mysite.mydomain.com/testSearch/results?postcode=WN8+0BA 

测试的虚拟机本身的页面,它似乎相当愉快工作,所以我很满意Apache是​​否正确配置,并在虚拟机中运行。

然而,当我试图从我的主机的浏览器通过HTTPS访问虚拟机,我不能这样做。

我添加

config.vm.forward_port "https", 443, 8443 

我vagrantfile,但在尝试访问该网址

https://mysite.mydomain.com:8443/testSearch/results?postcode=WN8+0BA 

根本无法显示我已经与几个不同的浏览器尝试过的页面:IE给一个毫无意义的“Internet Explorer无法显示网页”;镀铬给人

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. 

火狐给我

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) 

但即使Firebug的Net选项卡并没有告诉我任何事情不止于此。

我没有收到在VM Apache的访问或错误日志任何东西,所以我怀疑是流浪汉不转发SSL可言。

  • VM来宾操作系统:centos56x64
  • 主持人:Windows 7的64位
  • 的JRuby:1.6.3(红宝石-1.8.7-P330)(2011-07-07 965162f)(Java的热点( TM)64位服务器VM 1.6.0_24)[视窗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 

2)访问您的VM “lucid32”

vagrant ssh 

3)你的虚拟机内部,配置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> 

4)退出VM和配置您的主机文件的“主机”:

33.33.33.10 your-domain.dev 
+6

当使用这种解决方案时,你必须做一遍又一遍的第2步和第3步,当你消灭流浪箱。使用配置(bash)脚本,Chef或Puppet将使这项任务重复得多。 –

+1

对于谷歌来说,我不得不将'SSLCertificateFile'指定为'.crt'文件,将'SSLCertificateKeyFile'指定为'.key'文件。 –

0

答案上面会要求你不断重复步骤2和3每次销毁箱时间。我建议你使用厨师来实现你的目标。看下面的例子:

# -*- mode: ruby -*- 
# vi: set ft=ruby : 

Vagrant.configure(2) do |config| 

    config.vm.box  = "precise64" 
    config.vm.box_url = "http://files.vagrantup.com/precise64.box" 

    config.vm.network :forwarded_port, guest: 80, host: 8080 
    config.vm.network :forwarded_port, guest: 443, host: 443 

    config.vm.network "private_network", ip: "192.168.33.10" 

    config.vm.provision :chef_solo do |chef| 

     chef.cookbooks_path = "/path/to/your/cookbooks" 

     # Install PHP 
     chef.add_recipe "php" 
     chef.add_recipe "php::module_mysql" 

     # Setup Apache 
     chef.add_recipe "apache2" 
     chef.add_recipe "apache2::mod_php5" 

     chef.json = { :apache => { :default_site_enabled => true } } 

    end 

end