14

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

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

它似乎工作得非常愉快,所以我很满意 apache 已正确配置并在 VM 中工作。

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

我已经添加

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

到我的 vagrantfile,但试图访问 url

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 的访问或错误日志中没有得到任何信息,所以我怀疑 vagrant 根本没有转发 ssl。

  • 虚拟机客户操作系统:centos56x64
  • 主机:Windows 7 64 位
  • JRuby:1.6.3 (ruby-1.8.7-p330) (2011-07-07 965162f) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_24) [Windows 7-amd64-java]
  • 流浪者:0.7.8
  • 虚拟盒子:4.0.12

我们将不胜感激地接受任何帮助。

4

2 回答 2

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)访问您的虚拟机“lucid32”

vagrant ssh

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>

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

33.33.33.10    your-domain.dev
于 2011-11-15T00:15:04.303 回答
0

上面的答案要求您每次销毁盒子时都重复步骤 2 和 3。我建议您使用 Chef 来实现您的目标。请参见下面的示例:

# -*- 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
于 2015-02-26T14:01:34.870 回答