请注意,我已经在Docker容器中部署了一个Lumen应用程序,运行Ubuntu和Apache 2.4,但我对该应用程序发出的所有请求都返回404,除了根目录。
以下是我通过阅读其他帖子所做的一些事情......
a2enmod rewrite
Require all granted
和AllowOverride All
添加到我的conf文件中的Directory指令这是我的000-default.conf文件的结构
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/public
<Directory /var/www/public>
Require all granted
AllowOverride All
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog /var/log/apache2/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
最后,当我运行php artisan route:list
时,我看到以下内容......
+------+------+------------+------------+---------+------------+
| Verb | Path | NamedRoute | Controller | Action | Middleware |
+------+------+------------+------------+---------+------------+
| GET | / | | None | Closure | |
+------+------+------------+------------+---------+------------+
请问,我该怎么办才能让它发挥作用?
编辑:这是我的.htaccess
文件
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Apache seems to discard the Authorization header if it is not a
# base64 encoded user/pass combo
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
编辑2:路线
$api = $app->make(Dingo\Api\Routing\Router::class);
$api->version('v1', [], function () use ($api) {
$api->get('/', function () {
return json_encode("Vendors API root");
});
$api->group(['prefix' => 'vendors', 'namespace' => 'App\Api\v1\Controllers'], function () use ($api) {
// Vendor API Endpoints
$api->get('/list', 'VendorController@listVendors');
$api->get('/{id}/get', 'VendorController@getVendor');
$api->post('/add', 'VendorController@addVendor');
});
});