简体   繁体   English

Laravel在Apache虚拟主机的所有路由上显示404

[英]Laravel showing 404 on all routes in Apache virtual host

I have two laravel apps that I wish to put on a live Apache server. 我有两个laravel应用,希望将它们放在实时Apache服务器上。 The os is CentOs. 操作系统是CentO。 I have followed this toturial to set up a virtual host: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-centos-7 我遵循这个惯例来建立虚拟主机: https ://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-centos-7

When I try to visit my links, http://lara.ci/public/ , all I get is 404 Not Found. 当我尝试访问链接http://lara.ci/public/时 ,得到的只是404 Not Found。 Below is my sites-available file: 以下是我的网站可用文件:

<VirtualHost *:80>

    ServerName www.lara.ci
    ServerAlias lara.ci
    DocumentRoot /var/www/lara.ci/public_html/public
    ErrorLog /var/www/lara.ci/error.log
    CustomLog /var/www/lara.ci/requests.log combined
</VirtualHost>

Files for the app is in public_html folder. 该应用程序的文件位于public_html文件夹中。 I even tried the approach below after searching all over but can't get it to work: 我搜索了全部之后甚至尝试了下面的方法,但是无法正常工作:

Set the following in httpd.conf 在httpd.conf中设置以下内容

<Directory />
AllowOverride All
</Directory>

My .htaccess file in public seems to be working because when I try something like below, I get the redirection. 我在公共场合的.htaccess文件似乎正在工作,因为当我尝试如下操作时,我获得了重定向。 Also mod_rewrite is enabled: 同时启用了mod_rewrite:

<IfModule mod_rewrite.c>
Redirect 301 / https://google.com
...

Appreciate assistance 感激的帮助

是正确的,尽管您的document_root已经指向公共子文件夹,但您仍将转到http://lara.ci/public吗?

The problem is in the fact that you are pointing the document root to: 问题在于您将文档根目录指向:

DocumentRoot /var/www/lara.ci/public_html/public

Its should be: 它应该是:

<VirtualHost *:80>
  ServerName www.lara.ci
  ServerAlias lara.ci
  DocumentRoot /var/www/lara.ci/public_html
  ErrorLog /var/www/lara.ci/error.log
  CustomLog /var/www/lara.ci/requests.log combined
</VirtualHost>

After digging around, I realise that my hidden files didn't copy such as .env, .gitignore etc since I was using the cp command to copy my files. 深入研究后,我意识到我的隐藏文件没有被复制,例如.env,.gitignore等,因为我正在使用cp命令复制文件。 To fix the problem, I ran the command like below (Source: https://superuser.com/questions/61611/how-to-copy-with-cp-to-include-hidden-files-and-hidden-directories-and-their-con ): 要解决此问题,我运行了如下命令(来源: https : //superuser.com/questions/61611/how-to-copy-with-cp-to-include-hidden-files-and-hidden-directories-和-他们的骗局 ):

cp -r /var/www/html/lara/.[^.]* /var/www/lara.ci/public_html which effectively copied all my hidden files and everything is working smoothly. cp -r /var/www/html/lara/.[^.]* /var/www/lara.ci/public_html ,它有效地复制了我所有的隐藏文件,并且一切运行正常。

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

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