无法从主机访问在 vagrant 中运行的 apache 2 服务器

无法从主机访问在 vagrant 中运行的 apache 2 服务器

我在 vagrant 客户机中运行 apache2。

以下是我的流浪文件-

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

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

  config.vm.box = "ubuntu/lunar64"

  config.vm.network "private_network", ip: "192.168.33.10"

   config.vm.provider "virtualbox" do |vb|
     vb.memory = "1024"
   end
   
   config.vm.provision "ansible_local" do |ansible|
    ansible.playbook = "provisioning/playbook.yml"
   end
end

我的剧本provisioning/playbook.yml如下 -

---
- hosts: all
  become: true
  tasks:
    - name: make sure we can connect
      ping:

    - name: update the apt cache
      apt: update_cache=yes cache_valid_time=3600

    - name: ensure apache2 is installed and up to date
      apt: name=apache2 state=latest

    - name: write the apache config file
      copy: src=templates/apache2/000-default.conf dest=/etc/apache2/sites-available/000-default.conf
      notify:
        - restart apache2

    - name: apache is running (and enable it at boot)
      service: name=apache2 state=started enabled=yes

  handlers:
    - name: restart apache2
      service: name=apache2 state=restarted

这里是provisioning/templates/apache2/000-default.conf-

<VirtualHost *:80>
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

命令vagrant up和运行正常。当我使用并vagrant provision登录 vagrant guest os 时,它运行正常vagrant sshcurl http://0.0.0.0

vagrant guest 操作系统截图

但是,当尝试使用客户机 IP 从主机操作系统访问时,它失败了 -

主机错误

如何在 vagrant machine 内部正确访问该服务?

相关内容