22

我正在为我的虚拟机使用 Laravel Homestead 2.0,并尝试在 YAML 文件 192.168.10.10 中的默认 IP 地址上为我的站点提供服务

我的 /etc/hosts 文件如下所示:

# Homestead
192.168.10.10   beta.dev
192.168.10.10   deploy.dev

我的 Homestead.yaml 文件如下所示:

---
ip: "192.168.10.10"
memory: 2048
cpus: 1

authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

folders:
    - map: ~/Projects
      to: /home/vagrant/Projects

sites:
    - map: beta.dev
      to: /home/vagrant/Projects/emorybeta/public
    - map: deploy.dev
      to: /home/vagrant/Projects/deploy/public

...

当我将我的域链接到 127.0.0.1 时,这些站点就会出现,但我必须将端口 8000 附加到 URL 的末尾(这没什么大不了的,我只想让指定的 IP 地址正常工作)。

有谁知道为什么当我的域指向 192.168.10.10 时我无法连接到服务器?


更新:

当我 ping deploy.dev 时,会显示正确的 IP 地址,但我的浏览器仍然无法连接到服务器。我认为这可能与优胜美地的 DNS 问题有关。

4

11 回答 11

8

几周前我遇到了同样的问题。

第一:确保您的文件夹路径正确,如果是,请仔细检查

下一步:运行 homestead destroy 和 homestead up 重新初始化虚拟机

如果这一切都不起作用:检查您家中是否有任何设备也可能在 192.168.10.10 上。

如果这一切都不起作用,那么您的问题可能更难解决,我建议为它制作一个 github 问题。

于 2015-01-23T15:26:58.493 回答
3

嘿,我遇到了同样的问题。我最终通过安装已弃用的 net-tools 包让它工作: sudo apt-get updatesudo apt-get install gnome-nettool

在此之后, homestead destroyhomestead up

这使我可以使用我在主机文件中指定的“域”从本地计算机的浏览器访问我的虚拟机站点 - 在您的情况下为 beta.dev 和 deploy.dev -而无需参考 localhost 或端口 8000。祝你好运,希望这个有帮助。

于 2015-08-28T12:36:17.263 回答
3

这是我为我的 Windows 10 机器所做的解决方案:

确保将持久路由添加到您的 vagrant box 在管理员命令提示符下输入 route -p add 192.168.10.0 mask 255.255.255.0 192.168.10.1

并确保您能够ping 192.168.10.10

还要检查为 virtualbox 仅主机适配器配置的 IP 地址是 192.168.10.1,掩码为 255.255.255.0

于 2015-09-09T02:56:34.507 回答
2

昨天我在 Homestead 5 上遇到了类似的问题。结果我的问题的原因是我运行了错误的 Vagrantfile。

一个实例应该对ip地址做出响应:192.168.10.10

为了纠正我的问题,我所做的是遵循以下说明: http: //laravel.com/docs/5.0/homestead

回顾一下:

在终端运行中:

vagrant box add laravel/homestead

然后

git clone https://github.com/laravel/homestead.git Homestead

然后

cd ./Homestead  

并从新的“Homestead”文件夹中运行此命令

bash init.sh

然后运行命令vagrant up并运行vagrant provision到应该在里面创建的 Vagrantfile./Homestead

以下是该vagrant provision命令在我的系统上的输出:

    vagrant provision
==> default: Running provisioner: file...
==> default: Running provisioner: shell...
    default: Running: inline script
==> default: Running provisioner: shell...
    default: Running: inline script
==> default: Running provisioner: shell...
    default: Running: /var/folders/q6/pgygb1ln4rg7_nvv0p8n1v300000gn/T/vagrant-shell20150714-94163-17xwlzk.sh
==> default: Running provisioner: shell...
    default: Running: /var/folders/q6/pgygb1ln4rg7_nvv0p8n1v300000gn/T/vagrant-shell20150714-94163-rncs6l.sh
==> default: nginx stop/waiting
==> default: nginx start/running, process 1751
==> default: php5-fpm stop/waiting
==> default: php5-fpm start/running, process 1766
==> default: Running provisioner: shell...
    default: Running: /var/folders/q6/pgygb1ln4rg7_nvv0p8n1v300000gn/T/vagrant-shell20150714-94163-e9qxwn.sh
==> default: Warning: Using a password on the command line interface can be insecure.
==> default: Warning: Using a password on the command line interface can be insecure.
==> default: Running provisioner: shell...
    default: Running: /var/folders/q6/pgygb1ln4rg7_nvv0p8n1v300000gn/T/vagrant-shell20150714-94163-14rlz2c.sh
==> default: Running provisioner: shell...
    default: Running: /var/folders/q6/pgygb1ln4rg7_nvv0p8n1v300000gn/T/vagrant-shell20150714-94163-16ethaq.sh
==> default: Running provisioner: shell...
    default: Running: inline script
==> default: Running provisioner: shell...
    default: Running: inline script
==> default: Running provisioner: shell...
    default: Running: inline script
==> default: php5-fpm stop/waiting
==> default: php5-fpm start/running, process 1861
==> default: Running provisioner: shell...
    default: Running: inline script
==> default: You are already using composer version 92faf1c7a83a73794fb914a990be435e1df373ca.
==> default: Running provisioner: shell...
    default: Running: /var/folders/q6/pgygb1ln4rg7_nvv0p8n1v300000gn/T/vagrant-shell20150714-94163-btuuhg.sh
于 2015-07-15T17:05:51.297 回答
2

在 ubuntu 上安装 net-tools 为我解决了这个问题

$ sudo install net-tools
$ vagrant destroy
$ vagrant up
于 2017-05-19T15:14:29.193 回答
2

我确实遇到了这个问题,结果发现由于加载 TLS 证书时出现错误,nginx 无法启动。该vagrant up命令不会报告 nginx 无法启动,或者任何端口无法绑定。

为了诊断这一点,我做了以下事情:

$ nmap homestead.app
Starting Nmap 7.01 ( https://nmap.org ) at 2017-10-03 16:16 NZDT
Nmap scan report for homestead.app (192.168.10.10)
Host is up (0.00077s latency).
Not shown: 995 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
1025/tcp open  NFS-or-IIS
3306/tcp open  mysql
5432/tcp open  postgresql

列表中没有端口 80。让我们再次检查端口 80。

$ nmap homestead.app -p 80
...
Host is up (0.00020s latency).
PORT   STATE  SERVICE
80/tcp closed http

所以它肯定是关闭的。访客日志说什么?vagrant ssh和...

    $ systemctl status nginx.service
    ...
    Active: failed (Result: exit-code) since Tue 2017-10-03 03:06:12 UTC; 1min 30s ago
    ...
 homestead systemd[1]: Starting A high performance web server and a reverse proxy server...
 homestead nginx[1250]: nginx: [emerg] PEM_read_bio_X509_AUX("/etc/nginx/ssl/homestead.app.crt") failed (SSL: error:0906D06C:PEM routines:PEM_read_bio:no start line:Expecting: TRUSTED CERTIFICA
 homestead nginx[1250]: nginx: configuration file /etc/nginx/nginx.conf test failed
 homestead systemd[1]: nginx.service: Control process exited, code=exited status=1
 homestead systemd[1]: Failed to start A high performance web server and a reverse proxy server.
 homestead systemd[1]: nginx.service: Unit entered failed state.
homestead systemd[1]: nginx.service: Failed with result 'exit-code'.

由于配置错误,Nginx 无法启动。PEM_read_bio_X509_AUX错误指向/etc/nginx/ssl/homestead.app.crt文件。配置中使用的文件在哪里?

$ sudo vim /etc/nginx/sites-enabled/homestead.app

我注释掉了相关行:

@@ -1,6 +1,6 @@
 server {
     listen 80;
-    listen 443 ssl http2;
+#    listen 443 ssl http2;
     server_name homestead.app;
     root "/home/vagrant/Code/public";

@@ -42,7 +42,7 @@ server {
         deny all;
     }

-    ssl_certificate     /etc/nginx/ssl/homestead.app.crt;
-    ssl_certificate_key /etc/nginx/ssl/homestead.app.key;
+#    ssl_certificate     /etc/nginx/ssl/homestead.app.crt;
+#    ssl_certificate_key /etc/nginx/ssl/homestead.app.key;
 }

启动 nginx并从主机再次$ sudo service start nginx运行。nmap

$ nmap homestead.app -p 80,443
...
PORT   STATE SERVICE
80/tcp open  http
443/tcp closed https

端口 80 已打开,现在应该可以从http://homestead.app访问。当然 TLS 不起作用,但您应该能够通过生成新证书来修复它。我不确定证书无法加载的原因。

于 2017-10-03T03:35:58.050 回答
1

我有同样的情况,但我做出了改变。

我用这个 IP 改变了我的 /etc/hosts 文件127.0.0.1

于 2015-02-05T17:53:27.927 回答
1

vagrant up在我的情况下,通过安装来宾添加解决了问题:

~/Homestead (master|✔) $ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'laravel/homestead' is up to date...
==> 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
[...]
GuestAdditions versions on your host (5.0.26) and guest (5.0.20) do not match.
[...]
Copy iso file /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso
mount: /dev/loop0 is write-protected, mounting read-only
Installing Virtualbox Guest Additions 5.0.26 - guest version is 5.0.20
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.0.26 Guest Additions for Linux............
VirtualBox Guest Additions installer
Removing installed version 5.0.20 of VirtualBox Guest Additions...
Removing existing VirtualBox DKMS kernel modules ...done.
Removing existing VirtualBox non-DKMS kernel modules ...done.
Copying additional installer modules ...
Installing additional modules ...
Removing existing VirtualBox DKMS kernel modules ...done.
Removing existing VirtualBox non-DKMS kernel modules ...done.
Building the VirtualBox Guest Additions kernel modules ...done.
Doing non-kernel setup of the Guest Additions ...done.
You should restart your guest to make sure the new modules are actually used

此后,我得到了一个带有预期 IP 地址的新接口:

enp0s8    Link encap:Ethernet  HWaddr 08:00:27:e8:04:04
          inet addr:192.168.8.10  Bcast:192.168.8.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fee8:404/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:996 (996.0 B)
于 2016-10-03T15:31:19.373 回答
1

我的 Windows 机器上出现了这个问题,结果发现我不小心颠倒了文件夹部分“map”和“to”。当我发现文件夹不在 vagrant ssh 会话中的 ~/code/ 下时,很明显它工作不正常,但仔细检查路径并没有产生任何结果。

这是在 Windows 机器上映射文件夹部分的正确方法:

folders:
    - map: D:/Development/PHP/projects/
      to: /home/vagrant/code
于 2017-08-10T17:22:02.150 回答
0

使用这个 Vagrant 插件

vagrant plugin install vagrant-hostmanager

然后在您的宅基地文件夹中运行它以再次配置

vagrant reload --provision

这样你就不需要每次添加新项目时都更新主机文件了!

于 2021-06-03T04:00:15.243 回答
0

唯一的原因是需要将主机名和 IP 放在主机文件中

C:\Windows\System32\驱动程序\等

  • 以管理员身份打开记事本
  • 单击打开文件并选择“主机”文件
  • 输入您的域名(例如 192.168.10.10 homestead.app)
  • 保存(确保您保存为管理员)

完毕!

于 2021-05-26T14:54:03.260 回答