Laravel homestead multiple sites choose which one

2019-07-17 06:19发布

问题:

I have multiple sites in laravel homestead. Now, I want to access a spezific site via the ip in my local network. But I get allways the site I dont want...

homestead.yaml

sites:
- map: mdb.local
  to: /home/vagrant/code/mdb/public
  type: "apache"

- map: zz.tested
  to: /home/vagrant/code/abc/public
  type: "apache"

- map: 192.168.10.10
  to: /home/vagrant/code/mdb/public

And my hosts

192.168.10.10 mdb.local
192.168.10.10 zz.tested

I can access both on my computer with the domain, however I allways get abc over the ip in the local network. What do I have to change to get mdb on mobile and abc is accessable only on my computer?

I've read this StackOverflow Question but - you can see my implementation of this solution - it doesn't help to solve this problem.

回答1:

Apache always takes the first site alphabetically and returns that as the default host. What you can do is to make a host called 000default or similar, which will then be returned when there's no hostname.



回答2:

You can accomplish this by configuring the second app/site to run on port 81 rather than port 80, and then setting up a port forward to send 8001 or 8100 to 81.

sites:
- map: mdb.local
  to: /home/vagrant/code/mdb/public
  type: "apache"
  port: 81

- map: zz.tested
  to: /home/vagrant/code/abc/public
  type: "apache"

ports:
  - send: 8100
    to: 81

With this, you should be able to access your mdb application via the correct port. From inside Homestead, that would be 81. From outside, that would be 8100. The port is needed regardless of whether you are using the host machine's IP address (e.g. http://192.168.1.5:8100) or a hosts entry (e.g. http://mdb.local:8100).