在AWS EC2上部署laravel时出现404错误 [英] 404 Error when deploying laravel on AWS EC2

查看:122
本文介绍了在AWS EC2上部署laravel时出现404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Amazon EC2(Linux AMI)上部署Laravel.我在 larval 目录和 laravel/public 目录中添加 .htaccess .

I am trying to deploy Laravel on Amazon EC2 (Linux AMI). I add .htaccess in the larval directory and laravel/public directory.

<IfModule mod_rewrite.c>
WriteEngine On
RewriteBase /laravel/public/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

当我浏览 http://www.mydomaine.com/laravel/public 时,laravel第一页工作良好,但是当我浏览至 http://www.mydomaine.com/laravel/public/login ,出现 404 Not Found 错误.如何解决这个问题,谢谢您的帮助!

When I browser the http://www.mydomaine.com/laravel/public, the laravel first page works well, but when I browser into a sub page like http://www.mydomaine.com/laravel/public/login, a 404 Not Found error appears. How to solve this problem, thanks for your help !

推荐答案

您做错了.不要在 public 目录内的 .htaccess 文件中进行任何更改,也不要将 .htaccess 添加到Laravel根目录中.

You're doing it wrong. Do no make any changes in a .htaccess file inside a public directory and do not add .htaccess to a Laravel root directory.

您需要将Laravel指向 public 目录才能使其正常工作.例如,如果您已将Laravel安装在/path_to_laravel/public/目录中,则需要在Apache配置中使用以下设置:

You need to point Laravel to a public directory to make it work. For example, if you've installed Laravel in /path_to_laravel/public/ directory, you need to use these settings in your Apache config:

DocumentRoot "/path_to_laravel/public/"
<Directory "/path_to_laravel/public/">

重新启动Apache之后,您的应用程序应可按预期运行.

After that restart Apache and your app should work as expected.

使用不带'laravel'和'public'的URL,例如 http://www.mydomaine.com/login .

Use URLs, like http://www.mydomaine.com/login without 'laravel' and 'public'.

这篇关于在AWS EC2上部署laravel时出现404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆