【问题标题】:Vagrant: 192.168.33.10 refused to connectVagrant:192.168.33.10 拒绝连接
【发布时间】:2016-05-08 23:05:03
【问题描述】:

你好,我通过vagrant在虚拟机中安装了centOS6,还安装了httpd和php。

但是,当我尝试访问我在 Vagrantfile 中设置的 IP 地址http://192.168.33.10 时,我无法打开网页。

我在/var/www/html目录下做了一些文件。

$ cd /var/www/html/
$ ls
index.html  test.php

这是我在 Vagrantfile 中更改设置的地方

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  config.vm.network "forwarded_port", guest: 80, host: 8080

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  config.vm.network "private_network", ip: "192.168.33.10"

httpd 正在运行

$ which httpd
/usr/sbin/httpd


[vagrant@localhost ~]$ sudo service httpd status
Redirecting to /bin/systemctl status  httpd.service
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
   Active: active (running) since Sun 2016-05-08 18:44:38 EDT; 53s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 3180 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─3180 /usr/sbin/httpd -DFOREGROUND
           ├─3181 /usr/sbin/httpd -DFOREGROUND
           ├─3182 /usr/sbin/httpd -DFOREGROUND
           ├─3183 /usr/sbin/httpd -DFOREGROUND
           ├─3184 /usr/sbin/httpd -DFOREGROUND
           └─3185 /usr/sbin/httpd -DFOREGROUND

May 08 18:44:37 localhost.localdomain httpd[3180]: AH00558: httpd: Could not reliably determine the server's fully qualifie...ssage
May 08 18:44:38 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.

我对网络的东西了解不多。

我该如何解决这个问题? 谁能教教我!

附加信息 - 完整的 Vagrantfile

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

    # All Vagrant configuration is done below. The "2" in Vagrant.configure
    # configures the configuration version (we support older styles for
    # backwards compatibility). Please don't change it unless you know what
    # you're doing.
    Vagrant.configure(2) do |config|
      # The most common configuration options are documented and commented below.
      # For a complete reference, please see the online documentation at
      # https://docs.vagrantup.com.

      # Every Vagrant development environment requires a box. You can search for
      # boxes at https://atlas.hashicorp.com/search.
      config.vm.box = "centOS70_64"

      # Disable automatic box update checking. If you disable this, then
      # boxes will only be checked for updates when the user runs
      # `vagrant box outdated`. This is not recommended.
      # config.vm.box_check_update = false

      # Create a forwarded port mapping which allows access to a specific port
      # within the machine from a port on the host machine. In the example below,
      # accessing "localhost:8080" will access port 80 on the guest machine.
      config.vm.network "forwarded_port", guest: 80, host: 8080

      # Create a private network, which allows host-only access to the machine
      # using a specific IP.
      config.vm.network "private_network", ip: "192.168.33.10"

      # Create a public network, which generally matched to bridged network.
      # Bridged networks make the machine appear as another physical device on
      # your network.
      # config.vm.network "public_network"

      # Share an additional folder to the guest VM. The first argument is
      # the path on the host to the actual folder. The second argument is
      # the path on the guest to mount the folder. And the optional third
      # argument is a set of non-required options.
      # config.vm.synced_folder "../data", "/vagrant_data"

      # Provider-specific configuration so you can fine-tune various
      # backing providers for Vagrant. These expose provider-specific options.
      # Example for VirtualBox:
      #
      # config.vm.provider "virtualbox" do |vb|
      #   # Display the VirtualBox GUI when booting the machine
      #   vb.gui = true
      #
      #   # Customize the amount of memory on the VM:
      #   vb.memory = "1024"
      # end
      #
      # View the documentation for the provider you are using for more
      # information on available options.

      # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
      # such as FTP and Heroku are also available. See the documentation at
      # https://docs.vagrantup.com/v2/push/atlas.html for more information.
      # config.push.define "atlas" do |push|
      #   push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
      # end

      # Enable provisioning with a shell script. Additional provisioners such as
      # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
      # documentation for more information about their specific syntax and use.
      # config.vm.provision "shell", inline: <<-SHELL
      #   sudo apt-get update
      #   sudo apt-get install -y apache2
      # SHELL
    end

附加信息 - 我在执行 vagrant up 时得到什么。

% vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 80 (guest) => 8080 (host) (adapter 1)
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default:
    default: Guest Additions Version: 4.3.14
    default: VirtualBox Version: 5.0
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => /Users/Hayato/Dropbox/vagrant/centOS65
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.

【问题讨论】:

  • 你能发布你的完整配置文件吗?随意掩盖任何机密内容。
  • 感谢您的帮助!我添加了完整的 Vagrantfile。
  • 我看到配置文件有一些错误;当你流浪时你会得到什么
  • 当我从 vagrant ssh 退出时,它显示与 127.0.0.1 的连接已关闭。它应该是怎样的? [vagrant@localhost html]$ exit 与 127.0.0.1 的连接已关闭。
  • 我刚刚在帖子底部添加了我在做 vagrant up 时得到的内容。感谢您的支持。

标签: vagrant vagrantfile


【解决方案1】:

首先:使用fix IP时不需要转发端口;确实,您将直接从您的固定 IP 到达 80 端口

所以删除转发端口并重试。

第二个:下面的错误不清楚

5 月 8 日 18:44:37 localhost.localdomain httpd[3180]: AH00558: httpd: 无法可靠地确定服务器的完全合格...ssage

您是否在 conf 文件中使用 localhost 作为服务器名称?如果你删除它并让 apache 进行配置和绑定

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-12
    • 2015-03-24
    • 2021-03-08
    • 1970-01-01
    • 2017-08-08
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    相关资源
    最近更新 更多