2011-08-12 178 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