使用 ssl(端口转发)在 vagrant 沙箱上访问 apache

发布于 2024-11-29 09:01:59 字数 1478 浏览 3 评论 0原文

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

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

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

但是,当我尝试通过 https 从主机浏览器访问虚拟机时,我无法执行此操作。

我已经添加

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

到我的vagrantfile中,但是尝试访问该url

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

根本无法显示我用几种不同的浏览器尝试过的页面: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.

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)

,但即使是 Firebug Net 选项卡也没有告诉我更多信息。

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

  • VM 来宾操作系统: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]
  • Vagrant:0.7.8
  • VirtualBox: 4.0.12

如有任何帮助,我们将不胜感激。

I've built a vagrant/virtualbox web server as a development sandbox, and configured apache in the VM for ssl (on the default port 443, with a self-signed certificate). I've tested pages on the VM itself using curl

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

and it seems to work quite happily, so I'm satisfied that apache is correctly configured and working in the VM.

However, when I try to access the VM from my host's browsers over https, I'm unable to do so.

I've added

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

to my vagrantfile, but trying to access the url

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

simply can't display the page I've tried with several different browsers: IE gives a meaningless "Internet Explorer cannot display the webpage"; Chrome gives

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.

Firefox gives me

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)

but even the Firebug Net tab doesn't tell me anything more than that.

I'm not getting anything in the access or error logs on the VM apache, so I suspect that vagrant isn't forwarding the ssl at all.

  • VM Guest OS: centos56x64
  • Host: Windows 7 64-bit
  • 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]
  • Vagrant: 0.7.8
  • VirtualBox: 4.0.12

Any assistance would be gratefully accepted.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我纯我任性 2024-12-06 09:01:59

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) 在您的 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>

< strong>4) 退出虚拟机并在主机中配置文件“hosts”:

33.33.33.10    your-domain.dev

1) Configure the file 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) Access your VM "lucid32"

vagrant ssh

3) Inside your VM, configure the Apache "Virtual Host":

<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) Exit VM and configure the file "hosts" in your host machine:

33.33.33.10    your-domain.dev
不及他 2024-12-06 09:01:59

上述答案要求您每次销毁盒子时不断重复步骤 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

The answer above would require you to keep repeating steps 2 and 3 each time you destroy the box. I'd suggest you use Chef to achieve your goal. See the example below:

# -*- 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文