homestead 添加域名的问题

我的是win7操作系统,homestead安装并启动成功
现在运行视频里方法,添加域名和指向,就会这样:

vagrant@homestead:~$ serve homesteade.app /home/vagrant/Code/Laravel/public
dos2unix: converting file /vagrant/scripts/serve-laravel.sh to Unix format ...

就换行了,找了很多地方,都没找到解决方法,请指教

JellyBool

你直接在 Homestead.yaml 文件添加 域名吧,然后在 Homestead 目录执行

 vagrant reload --provision
John Howard 回复 @JellyBool

但是在本机打开指向的域名,会跳转到本机的:127.0.0.1的首页

JellyBool 回复 @John Howard

你配置你的 hosts 文件了么?

John Howard 回复 @JellyBool

配置了:
192.168.10.10 homestead.app

sites:
    - map: homestead.app
      to: /home/vagrant/Code/Laravel/public
JellyBool 回复 @John Howard

你执行这个出来的是什么?

 vagrant reload --provision
John Howard 回复 @JellyBool
$ vagrant reload --provision
==> homestead-7: Attempting graceful shutdown of VM...
==> homestead-7: Checking if box 'laravel/homestead' is up to date...
==> homestead-7: Clearing any previously set forwarded ports...
==> homestead-7: Clearing any previously set network interfaces...
==> homestead-7: Preparing network interfaces based on configuration...
    homestead-7: Adapter 1: nat
    homestead-7: Adapter 2: hostonly
==> homestead-7: Forwarding ports...
    homestead-7: 80 (guest) => 8000 (host) (adapter 1)
    homestead-7: 443 (guest) => 44300 (host) (adapter 1)
    homestead-7: 3306 (guest) => 33060 (host) (adapter 1)
    homestead-7: 5432 (guest) => 54320 (host) (adapter 1)
    homestead-7: 22 (guest) => 2222 (host) (adapter 1)
==> homestead-7: Running 'pre-boot' VM customizations...
==> homestead-7: Booting VM...
==> homestead-7: Waiting for machine to boot. This may take a few minutes...
    homestead-7: SSH address: 127.0.0.1:2222
    homestead-7: SSH username: vagrant
    homestead-7: SSH auth method: private key
==> homestead-7: Machine booted and ready!
==> homestead-7: Checking for guest additions in VM...
==> homestead-7: Setting hostname...
==> homestead-7: Configuring and enabling network interfaces...
==> homestead-7: Mounting shared folders...
    homestead-7: /vagrant => D:/Homestead
    homestead-7: /home/vagrant/Code => C:/Users/江政昊/Code
==> homestead-7: Running provisioner: file...
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: inline script
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: inline script
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: inline script
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: D:/Users/JOHNHO~2/AppData/Local/Temp/vagrant-shell20170107-20148-1bh5sfq.sh
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Creating Site: homestead.app
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Restarting Nginx
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Creating MySQL Database: homestead
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Creating Postgres Database: homestead
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Clear Variables
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Update Composer
==> homestead-7: You are already using composer version 1.3.0 (stable channel).
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: D:/Users/JOHNHO~2/AppData/Local/Temp/vagrant-shell20170107-20148-uz1pkj.sh
JellyBool 回复 @John Howard

这样还是不行么?看这里的信息显示已经成功创建你的站点了的。

John Howard 回复 @JellyBool

打开homestead.app 会显示本地localhost页面

JellyBool 回复 @John Howard

额。。你的 hosts 文件我看看,你可以正常使用 Homestead 么?比如连数据库,ssh 登录等

John Howard 回复 @JellyBool

192.168.10.10 homestead.app
是我的hosts文件,就一行
我可以ssh登录进去,也可以ping 通 192.168.10.10
但是我退出,会显示:

vagrant@homestead:~/Code/Laravel$ logout
Connection to 127.0.0.1 closed.
JellyBool 回复 @John Howard

这个Connection to 127.0.0.1 closed.是正常,你尝试把域名改一下,改成 192.168.10.10 homestead.dev,然后 Homestead.yaml 也对应改个域名,再 vagrant reload --provision 一次试试

John Howard 回复 @JellyBool

.dev 的还是不行,数据库通过33060端口可以正常连接
感觉我和homestead无缘了,哈哈

JellyBool 回复 @John Howard

这就尴尬了,我看不出什么错误了,而且感觉你的操作和反馈来说都是正常的

John Howard 回复 @JellyBool

Jelly,这个问题我找到原因了,现在访问homestead.dev:8000 端口是可以访问的
问题是如何不用8000端口,直接访问呢?

John Howard 回复 @JellyBool
vagrant@homestead:~$ ifconfig
enp0s3    Link encap:Ethernet  HWaddr 08:00:27:c3:0a:85
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fec3:a85/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:720 errors:0 dropped:0 overruns:0 frame:0
          TX packets:485 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:77261 (77.2 KB)  TX bytes:65437 (65.4 KB)

enp0s8    Link encap:Ethernet  HWaddr 08:00:27:04:93:f9
          inet addr:192.168.10.10  Bcast:192.168.10.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe04:93f9/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4 errors:0 dropped:0 overruns:0 frame:0
          TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:519 (519.0 B)  TX bytes:1296 (1.2 KB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:50 errors:0 dropped:0 overruns:0 frame:0
          TX packets:50 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1
          RX bytes:26161 (26.1 KB)  TX bytes:26161 (26.1 KB)

这个是我在homestead里运行ifconfig后的显示结果

newboss8 回复 @John Howard

我遇到了同样的问题,但是我加上:8000 是不能访问,不加的话,会跳到我第一个配置去,请问朋友最后是怎么解决的。

newboss8 回复 @JellyBool

请问老大,我也遇到了同样的问题, 但是我不希望用vagrant reload --provision
有没其它办法呢。

JellyBool 回复 @newboss8

我暂时没有,我就是用的 vagrant reload --provision

newboss8 回复 @JellyBool

难道这个版本通过serve命令添加站点就不行了么。。。
我试了一哈,vagrant reload --provision 是没有问题的,但是这种方法会重建数据库
我看到你有一个视频中是通过,serve 添加的。

JellyBool 回复 @newboss8

嗯哼,之前就是通过 serve 命令来的,我看了一下脚本,感觉也是没有什么问题。

现在使用的话,可以这个样子, ssh 进入 vagrant 的 homestead 虚拟机:

sudo bash /vagrant/scripts/serve-laravel.sh domain path
# 比如 sudo bash /vagrant/scripts/serve-laravel.sh pay-dev.net /home/vagrant/Code/laravist-pay/public

再在mac修改 hosts:

192.168.10.10  pay-dev.net

这样应该就可以了

newboss8 回复 @JellyBool

按照你说的,我现在是这样操作的
假如已经有了一个项目 homestead.app 且能正常访问 并且welcome.blade.php内容修改为homestead
1:在 〜/Code/ 下新建项目 test 修改welcome.blade.php内容为test
2: ssh 进homestead
3: sudo bash /vagrant/scripts/serve-laravel.sh test.app /home/vagrant/Code/test/public

试了一下,这个其实是跟 serve一样的结果 都是在/etc/nginx/sites-enabled/ 下新增一个配置文件 test.app
4: 修改 hosts 追加 192.168.10.10 test.app
5:访问test.app 出现的内容是 homestead

  也就是说test.app 没有成功映射到 /home/vagrant/Code/test 目录

  我ssh到homestead 后 nginx -t 会报如下错误 (没增加时不报任何错误):

nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
2017/05/01 12:55:18 [warn] 2277#2277: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
2017/05/01 12:55:18 [emerg] 2277#2277: BIO_new_file("/etc/nginx/ssl/test.app.crt") failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/etc/nginx/ssl/test.app.crt','r') error:2006D080:BIO routines:BIO_new_file:no such file)
nginx: configuration file /etc/nginx/nginx.conf test failed

并且不用命令增加站点 通过修改yaml文件然后reload --provision 一切正常

最后, 感谢你百忙之中抽空回答我的问题,laravist让我学会了很多。我会一如继往的支持

JellyBool 回复 @newboss8
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
2017/05/01 12:55:18 [warn] 2277#2277: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
2017/05/01 12:55:18 [emerg] 2277#2277: BIO_new_file("/etc/nginx/ssl/test.app.crt") failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/etc/nginx/ssl/test.app.crt','r') error:2006D080:BIO routines:BIO_new_file:no such file)
nginx: configuration file /etc/nginx/nginx.conf test failed

这个报错的话,感觉是脚本生成 ssl cert 的时候出了问题,还有就是 使用 sudo 执行脚本的时候,会造成这个 /var/log/nginx/error.log 文件的访问权限不对。感觉是要解决这两个问题就好了

newboss8 回复 @JellyBool

嗯 我先不纠结这个问题了, 先用着。说不定哪天突然在哪里找到办法解决了呢 哈哈

wenjie_zheng

ping homestead.app 的结果是什么?

John Howard 回复 @wenjie_zheng

192.168.10.10

jayin

vagrant 有没有国内镜像,下载好慢啊

JellyBool 微信公众号

不定期送书,送键盘,送订阅优惠