php Laravel 宅基地 IP 地址不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28036879/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:40:03  来源:igfitidea点击:

Laravel homestead IP address not working

phplaravelvagrantvirtualboxhomestead

提问by evcohen

I'm using Laravel Homestead 2.0 for my VM and am trying to serve my sites on the default IP address in the YAML file 192.168.10.10

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

My /etc/hosts file looks like this:

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

# Homestead
192.168.10.10   beta.dev
192.168.10.10   deploy.dev

My Homestead.yaml file looks like this:

我的 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

...

The sites come up when I link my domains to 127.0.0.1 but I have to append port 8000 onto the end of the URL (which isn't a big deal, I just want to get the specified IP address to work).

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

Does anyone know why I cannot connect to server when my domains are pointed to 192.168.10.10?

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



UPDATE: 更新:

When I ping deploy.dev the right IP address shows up, but still my browser can't connect to the server. I'm thinking it might have something to do with DNS issues in Yosemite.

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

采纳答案by Nick

I had the same problems a few weeks ago.

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

First: make sure your folder paths are correct, if so, double check it

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

Next: run homestead destroy and homestead up to reinitialize the VM

Next: 运行 homestead destroy 和 homestead up 来重新初始化虚拟机

if that all didnt work: Check if you have any devices at home that might also be on 192.168.10.10.

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

If that all didnt work, your problem is probably alot harder to fix and i'd suggest making a github issue for it.

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

回答by Logan Graba

Hey I had this exact same problem. I eventually got it working by installing the deprecated net-tools package: sudo apt-get updateand sudo apt-get install gnome-nettool

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

After this, homestead destroyand homestead up

在这之后, homestead destroyhomestead up

This allowed me to access my virtual machine sites from my local machine's browser using the 'domains' I specified in the hosts file - in your case beta.dev and deploy.dev - withoutreferring to localhost or port 8000. Good luck, hope this helps.

这允许我使用我在主机文件中指定的“域”从我的本地机器的浏览器访问我的虚拟机站点 - 在你的情况下是 beta.dev 和 deploy.dev -无需引用本地主机或端口 8000。祝你好运,希望如此有帮助。

回答by neethumol

This is the solution I did for my Windows 10 machine:

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

Make sure you add a persistent route to your vagrant box In Administrator command prompt enter route -p add 192.168.10.0 mask 255.255.255.0 192.168.10.1

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

And make sure you are able to ping 192.168.10.10

并确保您能够ping 192.168.10.10

Also check the IP address configured for the virtualbox host-only adapter is 192.168.10.1 with mask 255.255.255.0

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

回答by Giovanni S

Installing net-tools on ubuntu fixed this for me

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

$ sudo install net-tools
$ vagrant destroy
$ vagrant up

回答by PeloNZ

I had exactly this issue, and it turned out that nginx was failing to start due to an error when loading the TLS certificates. The vagrant upcommand doesn't report that nginx failed to start, or that any ports failed to bind.

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

To diagnose this, I did the following:

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

$ 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

There is no port 80 in the list. Let's double-check port 80.

列表中没有端口 80。让我们仔细检查端口 80。

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

So it is certainly closed. What do the guest logs say? vagrant sshand...

所以它肯定是关闭的。客人日志说什么?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 has failed to start due to an error in it's config. The PEM_read_bio_X509_AUXerror points to the /etc/nginx/ssl/homestead.app.crtfile. Where is that file used in the configuration?

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

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

I commented out the related lines:

我注释掉了相关的几行:

@@ -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;
 }

Start nginx with $ sudo service start nginxand run nmapagain from the host.

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

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

Port 80 is open and should be accessible now from http://homestead.app. Of course TLS won't be working but you should be able to fix it by generating new certificates. I'm not sure of the reason for the certificates failing to load in the first place.

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

回答by Josh Maag

I had this issue come up on my Windows machine and it turns out I had accidentally reversed the folders section "map" and "to". When I found that the folder wasn't underneath ~/code/ in the vagrant ssh session it was obvious it wasn't working right, but double checking the paths didn't yield anything.

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

Here is the correct way to map the folder section on your Windows machine:

以下是在 Windows 计算机上映射文件夹部分的正确方法:

folders:
    - map: D:/Development/PHP/projects/
      to: /home/vagrant/code

回答by crishoj

In my case the problem was solved by letting vagrant upinstall the guest additions:

在我的情况下,问题是通过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

After this point, I got a new interface with the expected IP address:

在此之后,我得到了一个具有预期 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)

回答by navamario

I had the same situation, but I made a change.

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

I changed my /etc/hosts file with this IP 127.0.0.1

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

回答by Nate Flink

I had a similar issue yesterday for Homestead 5. It turned out the cause of my problem was that I was running the wrong Vagrantfile.

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

An instance should give a response to the ip address: 192.168.10.10

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

To correct the problem in my case what I did was to follow these instructions: http://laravel.com/docs/5.0/homestead

为了纠正我的问题,我所做的是按照以下说明进行操作:http: //laravel.com/docs/5.0/homestead

To recap:

回顾一下:

In terminal run:

在终端运行中:

vagrant box add laravel/homestead

then

然后

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

then

然后

cd ./Homestead  

and run this command FROM INSIDE the new "Homestead" folder

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

bash init.sh

then run the commands vagrant upand vagrant provisionto that Vagrantfile, that should have been created inside ./Homestead

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

Here is what the output of the vagrant provisioncommand looks like on my system:

这是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