简体   繁体   English

在AWS EC2上部署laravel时出现404错误

[英]404 Error when deploying laravel on AWS EC2

I am trying to deploy Laravel on Amazon EC2 (Linux AMI) . 我正在尝试在Amazon EC2(Linux AMI)上部署Laravel。 I add .htaccess in the larval directory and laravel/public directory. 我在larval目录和laravel/public目录中添加.htaccess

<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>

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. 当我浏览http://www.mydomaine.com/laravel/public ,laravel第一页效果很好,但是当我浏览至子页面(如http://www.mydomaine.com/laravel/public/login ,出现404 Not Found错误。 How to solve this problem, thanks for your help ! 如何解决这个问题,谢谢您的帮助!

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. 不要在public目录中的.htaccess文件中进行任何更改,也不要将.htaccess添加到Laravel根目录中。

You need to point Laravel to a public directory to make it work. 您需要将Laravel指向public目录才能使其正常工作。 For example, if you've installed Laravel in /path_to_laravel/public/ directory, you need to use these settings in your Apache config: 例如,如果您在/path_to_laravel/public/目录中安装了Laravel,则需要在Apache配置中使用以下设置:

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

After that restart Apache and your app should work as expected. 之后,重新启动Apache,您的应用程序将按预期运行。

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

Doing as Alexey said should make it work. 像Alexey所说的那样做应该可以使它工作。 However, if you really want your application to be in this specific path ( /laravel/public/ ), you might add a new directive to your apache conf file. 但是,如果您确实希望应用程序位于此特定路径( /laravel/public/ )中,则可以向apache conf文件中添加一个新指令。

Add a ServerName "localhost.app/my/path" and restart your Apache and it should work. 添加一个ServerName "localhost.app/my/path"并重新启动Apache,它应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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