[英]Laravel Homestead PHP: Running projects on computer's IP Address
[英]Laravel homestead IP address not working
我正在为我的 VM 使用 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 问题有关。
几周前我遇到了同样的问题。
首先:确保您的文件夹路径正确,如果是,请仔细检查
Next: 运行 homestead destroy 和 homestead up 来重新初始化虚拟机
如果这一切都不起作用:检查您家里是否有任何设备也可能在 192.168.10.10 上。
如果这一切都不起作用,那么您的问题可能更难解决,我建议为它创建一个 github 问题。
嘿,我遇到了完全相同的问题。 我最终通过安装已弃用的 net-tools 包使其工作: sudo apt-get update
和sudo apt-get install gnome-nettool
此后, homestead destroy
, homestead up
这使我可以使用我在主机文件中指定的“域”从本地计算机的浏览器访问我的虚拟机站点 - 在您的情况下是 beta.dev 和 deploy.dev -无需参考本地主机或端口 8000。祝你好运,希望如此有帮助。
这是我为我的 Windows 10 机器所做的解决方案:
确保将持久路由添加到 vagrant 框在管理员命令提示符下输入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
在 ubuntu 上安装 net-tools 为我解决了这个问题
$ sudo install net-tools
$ vagrant destroy
$ vagrant up
我遇到了这个问题,结果是 nginx 由于加载 TLS 证书时出错而无法启动。 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;
}
使用$ 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 将无法工作,但您应该能够通过生成新证书来修复它。 我不确定证书无法首先加载的原因。
我有同样的情况,但我做了改变。
我用这个 IP 127.0.0.1
更改了我的 /etc/hosts 文件
昨天我在 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
在我的情况下,问题是通过让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)
我在我的 Windows 机器上出现了这个问题,结果我不小心颠倒了文件夹部分“map”和“to”。 当我发现该文件夹不在 vagrant ssh 会话中的 ~/code/ 下时,很明显它无法正常工作,但仔细检查路径并没有产生任何结果。
以下是在 Windows 计算机上映射文件夹部分的正确方法:
folders:
- map: D:/Development/PHP/projects/
to: /home/vagrant/code
唯一的原因是需要将主机名和 IP 放在主机文件中
C:\\Windows\\System32\\drivers\\etc
完毕!
使用这个 Vagrant 插件
vagrant plugin install vagrant-hostmanager
然后在您的 homestead 文件夹中运行它以再次配置
vagrant reload --provision
这样就不用每次添加新项目都更新host文件了!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.