無法從主機存取在 vagrant 中執行的 apache 2 伺服器

無法從主機存取在 vagrant 中執行的 apache 2 伺服器

我在 vagrant guest machine 內運行 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 upvagrant provision運行良好。當我登入 vagrant guest os 時,vagrant ssh做的curl http://0.0.0.0工作正常

vagrant 來賓作業系統螢幕截圖

但是,當嘗試使用來賓電腦 IP 從主機作業系統存取時,它失敗了 -

主機錯誤

如何在vagrant機器內正確存取服務?

相關內容