简体   繁体   中英

Fresh Laravel install displays 403 Forbidden in Nginx

I have created a fresh Laravel application by using composer create-project command. Then I put all the folders and files in /usr/share/nginx/html/ , which is the default document root for my nginx server. However everytime I runs the http://localhost , it keeps displaying 403 Forbiden . I tried creating a testing index.php (<? php_info();) and it worked fine.

I've read somewhere that I need to set the containing folder (/html), as well as the app/storage folder permission to 777 but still no luck.

Please help me. Thank you in advance.

Here is the nginx default.conf

Laravel projects serve from the <projectName>/public directory. Make sure your nginx config is set up to look there for your index file and NOT in your <projectName> folder only.

Would you edit your question and paste your server config there?

I think it may because index.php is not in the index file list. check these lines:

index index.html index.php;

or

try_files $uri $uri/ =404;

The accepted answer is correct - Laravel services from the public folder and you need to tell nginx to look there - but also a little vague if you're bumping up against this problem. When you create new sites on a Homestead installation by adding them to your .yaml file and using vagrant provision or vagrant up --provision , the created nginx conf file will need editing before Laravel will serve files correctly.

Go to your CLI, and enter Homestead using vagrant ssh or homestead ssh . It will ask for your password, which by default is "vagrant".

Once you're in the virtual machine, type the following commands:

sudo nano /etc/nginx/sites-enabled/your-site-name-here

Then add /public to the end of the existing root near the top of the file (it'll be something like /home/vagrant/projects/your-site to begin with and save in Nano (ctrl+s), then exit nano (ctrl+x).

Once you've exited Nano, restart nginx using sudo nginx -s reload . Your routing will now work!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM