3

I am running Apache server with vagrant and I want to access multiple websites from host machine. Current setup looks like this:

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/hosts

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>

I can access the website from inside vagrant box by: curl https://website.com -k. How can I expose it to the host machine?

RNK
  • 5,582
  • 11
  • 65
  • 133

1 Answers1

3

The steps are correct.

  1. In your Vagrantfile you dont need to add the forwarding port if you use a static IP as you'll access your VM/guest using the IP directly

  2. You need to update the hosts file from your host machine. On windows the file is located under C:\Windows\System32\drivers\etc

You can now access https://website.com directly from your host

Frederic Henri
  • 51,761
  • 10
  • 113
  • 139