Accessing apache on a vagrant sandbox using ssl (port forwarding)

前端 未结 2 712
太阳男子
太阳男子 2021-02-01 23:53

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 te

相关标签:
2条回答
  • 2021-02-02 00:04

    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
    
    0 讨论(0)
  • 2021-02-02 00:18

    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
    
    0 讨论(0)
提交回复
热议问题