Laravel Homestead: 403 forbidden on nginx

2019-02-05 14:13发布

问题:

I just installed Laravel Homestead according to their instructions. When I open http://homestead.app:8000 I get the nginx 403 forbidden HTTP Response.

I have tried setting app/storage permissions to 755, but that didn't work, so I reloaded Vagrant. With no further result.

I also tried changing the nginx configuration, but with no success.

回答1:

I had the same problem and for me the cause was that in the Homestead.yaml file, I have incorrectly put this:

sites:
- map: homestead.app
  to: /home/vagrant/Code

Instead of the correct syntax:

sites:
- map: homestead.app
  to: /home/vagrant/Code/path/to/public


回答2:

Another reason for this response can be duplicating your routing with folders in public directory. For example you might have homestead.app/lists GET route and lists folder in your /public directory. This will cause the same 403 error (server will assume you are trying to access /public/lists directory instead of your /lists route).



回答3:

I have been banging my head against the wall dealing with this very same problem, and I just solved it for my case.

I was sure I'd set up the yaml file correctly, but I kept getting the 403 error, and when experimenting with some routes I was getting "input file not specified".

My solution came from http://laravel.com/docs/4.2/homestead and it involved using the serve command. I wasn't adding any additional sites, just trying to anything to get the first site running.

SSH'ing into my vagrant box and using the command "serve my_app_name.app /home/vagrant/Code/path/to/public" did the job. Note that I had already put an entry into my hosts file for this app.

Hope this helps someone.



回答4:

OK, i got the answer to the question after few hours of searching and debugging.

The problem:

  1. I've got GET route /admin
  2. Also i've got /public/admin/ folder with assets inside.
  3. And i've got 403 access denied from nginx cause of this duplication;

So, if you wont to rename route or assets folder, all you need to do is replace

location / {
    try_files $uri $uri/ /index.php?$query_string;
    #              ^^^^^
}

with this:

location / {
    try_files $uri /index.php?$query_string;
}

If you could rename your route or assets folder without any refactor then you could do this without nginx config fixing.

Hope this will be helpful.



回答5:

For some people this may be as simple as having git cloned in an existing public folder, e.g:

- map: hello-world.dev
  to: /home/vagrant/Code/Laravel/public/hello-world

The correct folder structure is:

- map: hello-world.dev
  to: /home/vagrant/Code/hello-world/public

Another good note is ignoring the laravel docs on editing hosts file, using git shell, or cygwin (windows) to install vagrant hostsupdater, and simply adding entries for hosts and aliases to ~/.homestead/Homestead.yaml file.



回答6:

I would suggest checking the nginx logs - use sudo tail /var/log/nginx/homestead.app-error.log



回答7:

Here's the full solution steps:

  1. run homestead edit

  2. add /public to the end of your directory

sites: - map: homestead.app to: /full/path/to/the/laravel-app/public

  1. run homestead halt && homestead up --provision


回答8:

Change the config of Nginx

Put that line in 'location /' section:

try_files $uri $uri/public/index.php?$query_string;

If its not working then replace your 'public' with the folder name that content 'index.php',

That worked great with me using ServerPilot,

Good luck!.



回答9:

In my case, for testing purposes I had only phpinfo.php file in the public directory. The server kept showing 403 errors until I placed a file named index.php into the public folder!



回答10:

Access in your browser

homestead.app/public

Before installation of laravel/laravel with composer within /home/vagrant/Code/Laravel/public



回答11:

In your case, you are getting nginx 403 forbidden HTTP Response because of improper configuration of sites in Homestead.yaml, if you configure it properly it should work.

How to solve the issue step by step:

1) Goto your vagrant box and create the laraval app

$vagrant ssh
$cd ~/code

$#lets create basic blog 
$laravel new blog
    Crafting application...
    Loading composer repositories with package information
    ........

$cd blog
$ll
   # You should be able to see public folder in this dir.
   # this is the entry point for your application.
   # this is your public dir: ~/code/blog/public
   # more explicitly: /home/vagrant/code/blog/public

$exit   # exit ssh

2) Update the Homestead.yaml with proper site info

 - map: homestead.app
   to: /home/vagrant/code/blog/public  # should be same as in step1

3) Re-provision your vagrant

$vagrant reload --provision

You should be able to access it now using http://homestead.app Thank you!



回答12:

I ran into this when I tried manually creating my first site. @GregD's answer helped me discover the problem! Vagrant/Homestead/Laravel will typically get everything running smoothly on its own if you use the built-in features.

Homestead's configuration file comes preconfigured for one site, located in /Code/Laravel/. Some steps to get this test bed up and running:

  1. Install Homestead (remember to set your hosts file)
  2. vagrant up and connect to your virtual machine via ssh (Chrome Secure Shell is great if you don't have a terminal on your machine already)
  3. Download and set up the PHAR package
  4. cd ~/Code
  5. laravel new Laravel.
  6. Browse to http://homestead.app:8000

This will create your first site with appropriate permissions. You can model future sites after the permissions on this one, or just use the "sites" node of Homestead.yaml and laravel new <site> to make new sites in the future.



回答13:

My solution was to move the address in the host file to the bottom of the file. It happend to me twice.



标签: laravel nginx