You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

新Laravel项目/login路由返回403 Forbidden错误求助

Troubleshooting Laravel /login 403 Forbidden on Homestead

Hey there, let's work through this frustrating 403 issue with your new Laravel project's login route. Since your /register route works perfectly and an older Laravel project (with the same /login setup, no .htaccess included) runs fine on Homestead, here are some focused steps to debug:

1. Verify Homestead's Nginx Site Configuration

Since you're seeing an nginx/1.13.3 403 response, the problem likely lies in your Nginx setup for the new project:

  • SSH into your Homestead box with homestead ssh
  • Navigate to the Nginx sites directory: cd /etc/nginx/sites-available/
  • Open your project's config file (e.g., your-project.test) and check two key things:
    • Ensure the root directive points to your project's public folder:
      root /home/vagrant/code/your-project/public;
      If it's pointing to the project root instead, Nginx will try to serve files directly without passing requests to Laravel's index.php, causing 403s.
    • Confirm the try_files line is correctly set to route all requests through Laravel:
      try_files $uri $uri/ /index.php?$query_string;

2. Fix Directory Permissions

New Laravel projects often run into permission issues on Homestead, which can trigger 403 errors. Run these commands inside your project directory (after SSHing into Homestead):

sudo chown -R www-data:www-data /home/vagrant/code/your-project
sudo chmod -R 755 /home/vagrant/code/your-project/storage /home/vagrant/code/your-project/bootstrap/cache

Your older project probably had these permissions set correctly already, which is why it works without issues.

3. Remove the Custom .htaccess File

Homestead uses Nginx, not Apache—so .htaccess files don't do anything here. The file you added might be causing unintended conflicts. Delete it, then restart Nginx to apply changes:

sudo service nginx restart

4. Clear Laravel Route Cache

Occasionally, cached routes can lead to unexpected routing behavior. Clear the cache with:

php artisan route:clear

Then try accessing /login again.

5. Check Nginx Error Logs for Exact Details

If none of the above works, the Nginx error log will tell you exactly what's causing the 403. Run this command and keep it running while you try to access /login:

sudo tail -f /var/log/nginx/error.log

Look for lines that appear when you hit the login route—they'll specify if it's a permission denied error, incorrect file path, or another issue.

If you still can't resolve it, share the contents of your Nginx site config and any relevant error log lines, and we can dive deeper!

内容的提问来源于stack exchange,提问作者Ognjen Stefanovic

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 07:23:48