我正在运行带有vagrant的Apache服务器,我想从主机访问多个网站。目前的设置如下:
Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.ssh.forward_agent = true
config.vm.network "forwarded_port", guest: 80, host: 80, host_ip: "127.0.0.1", id: 'apache_http'
config.vm.network "forwarded_port", guest: 443, host: 443, host_ip: "127.0.0.1", id: 'apache_https'
config.vm.network "forwarded_port", guest: 22, host: 22, host_ip: "127.0.0.1", id: 'ssh'
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.synced_folder ".", "/var/www/"
end
的/ etc /主机
127.0.0.1 localhost
192.168.33.10 website.com
192.168.33.10 a.website.com
192.168.33.10 b.website.com
/etc/apache2/sites-available/website.conf
<VirtualHost *:80>
ServerAdmin example@gmail.com
ServerName website.com
ServerAlias www.website.com
DocumentRoot /var/www/website/public_html
ErrorLog /var/www/website/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost _default_:443>
ServerName website.com
ServerAlias www.website.com
DocumentRoot /var/www/website/public_html
ErrorLog /var/www/website/error.log
SSLEngine on
SSLCertificateKeyFile /etc/apache2/ssl/website.key
SSLCertificateFile /etc/apache2/ssl/website.cert
</VirtualHost>
我可以通过以下方式从流氓框内访问该网站:curl https://website.com -k
。如何将其暴露给主机?
答案 0 :(得分:2)
步骤正确。
在您的Vagrantfile中,如果您使用静态IP,则不需要添加转发端口,因为您将直接使用IP访问您的VM /来宾
您需要从主机更新hosts文件。在Windows上,该文件位于C:\Windows\System32\drivers\etc
您现在可以直接从您的主机访问https://website.com