404使用apache2虚拟主机调用laravel 6.4中的api时出错



我在ubuntu 18.04上安装了Laravel 6.4,带有php 7.2和apache2。我已经构建了一个案例研究来开发api,当我执行php-artisan-serve命令并使用poster进行查询时,一切都很好。但是,如果我创建了一个虚拟主机,我可以毫无问题地查看网站,然而,当通过邮递员执行查询时,我会得到404错误。.htaccess文件是默认情况下带来laravel:的文件

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

我的虚拟主机如下:

<VirtualHost test-api.local:80>
ServerName test-api.local
DocumentRoot /var/www/html/restlav/public
DirectoryIndex index.php
ErrorLog ${APACHE_LOG_DIR}/test-api.local-error.log
CustomLog ${APACHE_LOG_DIR}/test-api.local-access.log combined
<Directory "/var/www/html/restlav">
Options +FollowSymLinks
RewriteEngine On
AllowOverride None
Require all granted
</Directory>
</VirtualHost>

我已经尝试过做出官方文件中建议的改变,但没有任何改变。重写模块已启用。如果有人能帮我,我会提前表示感谢。

在<目录>您需要将AllowOverride设置为All:的部分

<VirtualHost test-api.local:80>
ServerName test-api.local
DocumentRoot /var/www/html/restlav/public
DirectoryIndex index.php
ErrorLog ${APACHE_LOG_DIR}/test-api.local-error.log
CustomLog ${APACHE_LOG_DIR}/test-api.local-access.log combined
<Directory "/var/www/html/restlav">
Options +FollowSymLinks
RewriteEngine On
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

还要确保在apache服务器中启用重写模块:

$ sudo a2enmod rewrite

不要忘记最终重新启动apache服务器,使更改生效:

$ sudo systemctl restart apache2

最新更新