如何使用苏格兰威士忌2

时间:2016-09-15 21:53:28

标签: vagrant vagrantfile

我正在运行vagrant scotch box 2.0,我已经在框中添加了多个域。

我已将ip添加到我的主机文件

192.168.33.11 site1.local
192.168.33.11 site2.local

域名正在本地计算机上运行。

我想要做的是允许从网络上的另一台计算机访问这些网站

我已经向vagrant文​​件添加了一个端口,这适用于单个域环境。

但有没有办法以某种方式将域绑定在一起,从外部计算机上他们可以访问这两个域,只需添加一个不同的端口号,或者通过其他方式让两个站点在外部工作?

我不确定这是否相关,但是现在我在Mac上运行scotch box,但我需要解决方案也适用于Windows系统。

这是我的流浪文件

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

Vagrant.configure("2") do |config|

config.vm.box = "scotch/box"
config.vm.network "private_network", ip: "192.168.33.11"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.hostname = "scotchbox"
config.vm.synced_folder "/Users/acc/Documents/vagrant/site1", "/var/www/site1.local/public",id:"1", :mount_options => ["dmode=777", "fmode=666"]
config.vm.synced_folder "/Users/acc/Documents/vagrant/site2", "/var/www/site2.local/public",id:"2", :mount_options => ["dmode=777", "fmode=666"]
config.vm.provision "shell", inline: <<-SHELL

    ## Only thing you probably really care about is right here
    DOMAINS=("site1.local" "site2.local")

    ## Loop through all sites
    for ((i=0; i < ${#DOMAINS[@]}; i++)); do

        ## Current Domain
        DOMAIN=${DOMAINS[$i]}

        echo "Creating directory for $DOMAIN..."
        mkdir -p /var/www/$DOMAIN/public

        echo "Creating vhost config for $DOMAIN..."
        sudo cp /etc/apache2/sites-available/scotchbox.local.conf /etc/apache2/sites-available/$DOMAIN.conf

        echo "Updating vhost config for $DOMAIN..."
        sudo sed -i s,scotchbox.local,$DOMAIN,g /etc/apache2/sites-available/$DOMAIN.conf
        sudo sed -i s,/var/www/public,/var/www/$DOMAIN/public,g /etc/apache2/sites-available/$DOMAIN.conf

        echo "Enabling $DOMAIN. Will probably tell you to restart Apache..."
        sudo a2ensite $DOMAIN.conf

        echo "So let's restart apache..."
        sudo service apache2 restart

    done

SHELL

# Optional NFS. Make sure to remove other synced_folder line too
#config.vm.synced_folder ".", "/var/www", :nfs => { :mount_options => ["dmode=777","fmode=666"] }

end

1 个答案:

答案 0 :(得分:0)

答案是,其他域需要在不同的端口上运行,然后才能运行

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

Vagrant.configure("2") do |config|

config.vm.box = "scotch/box"
config.vm.network "private_network", ip: "192.168.33.11"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "forwarded_port", guest: 81, host: 8081
config.vm.network "forwarded_port", guest: 82, host: 8082
config.vm.hostname = "scotchbox"
config.vm.synced_folder "/Users/acc/Documents/vagrant/main", "/var/www/public",id:"3", :mount_options => ["dmode=777", "fmode=666"]
config.vm.synced_folder "/Users/acc/Documents/vagrant/site1", "/var/www/site1.local/public",id:"1", :mount_options => ["dmode=777", "fmode=666"]
config.vm.synced_folder "/Users/acc/Documents/vagrant/site2", "/var/www/site2.local/public",id:"2", :mount_options => ["dmode=777", "fmode=666"]
config.vm.provision "shell", inline: <<-SHELL

    ## Only thing you probably really care about is right here
    DOMAINS=("site1.local" "site2.local")

    IPS=("81" "82")

    ## Loop through all sites
    for ((i=0; i < ${#DOMAINS[@]}; i++)); do

        ## Current Domain
        DOMAIN=${DOMAINS[$i]}

        MYIP=${IPS[$i]}

        echo "Creating directory for $DOMAIN..."
        mkdir -p /var/www/$DOMAIN/public

        echo "Creating vhost config for $DOMAIN..."
        sudo cp /etc/apache2/sites-available/scotchbox.local.conf /etc/apache2/sites-available/$DOMAIN.conf

        echo "Updating vhost config for $DOMAIN..."
        sudo sed -i s,scotchbox.local,$DOMAIN,g /etc/apache2/sites-available/$DOMAIN.conf
        sudo sed -i s,/var/www/public,/var/www/$DOMAIN/public,g /etc/apache2/sites-available/$DOMAIN.conf

   sudo sed -i s,80,$MYIP,g /etc/apache2/sites-available/$DOMAIN.conf

   sudo sed -i s,'<VirtualHost',"Listen $MYIP \\n<VirtualHost",g /etc/apache2/sites-available/$DOMAIN.conf



        echo "Enabling $DOMAIN. Will probably tell you to restart Apache..."
        sudo a2ensite $DOMAIN.conf

        echo "So let's restart apache..."
        sudo service apache2 restart

    done

SHELL

# Optional NFS. Make sure to remove other synced_folder line too
#config.vm.synced_folder ".", "/var/www", :nfs => { :mount_options => ["dmode=777","fmode=666"] }

end