Laravel Homestead: 403 forbidden on nginx

后端 未结 16 2223
醉话见心
醉话见心 2020-12-30 19:17

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 s

相关标签:
16条回答
  • 2020-12-30 19:30

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

    0 讨论(0)
  • 2020-12-30 19:30

    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.

    0 讨论(0)
  • 2020-12-30 19:31

    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!

    0 讨论(0)
  • 2020-12-30 19:32

    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 don't want 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.

    0 讨论(0)
  • 2020-12-30 19:33

    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!

    0 讨论(0)
  • 2020-12-30 19:35

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

    0 讨论(0)
提交回复
热议问题