我正在使用新版本的 laravel 開發一個專案。我的其他專案都是以前的版本。我嘗試了每一種工匠清潔方法,以使一切變得清晰。我檢查了服務器請求,這些與我運行其他 laravel 8 專案的方式完全相同。
但是當我通過 Postman 請求我的 api 時,它回傳一個 404 頁面而不是實際操作。
路線:
GET|HEAD api/token ... generated::*** ? UserController@tokenRequest
api.php:
Route::get('token', [UserController::class, 'tokenRequest']);
我只是回傳一個帶有令牌的簡單回應。如果有 php 錯誤,我會看到它并且不會回傳 404,所以這很奇怪。我的其他專案也有同樣的問題,但或者這只是一個 mod_rewrite 問題,但我都檢查了這些選項。每個在 .conf 中都正確設定。我在我的 Ubuntu 20.04 服務器上使用 apache,就像我的其他專案一樣。唯一的區別是 Laravel 版本。
我使用的網址:
https://example.com/directory/api/token
我的公共目錄 url 運行良好。
https://example.com/directory/public
我的自定義域 .conf
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin [email protected]
DocumentRoot /var/www/html
<Directory /var/www/html>
Options -Indexes FollowSymLinks
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
CustomLog ${APACHE_LOG_DIR}/example.com.log combined
uj5u.com熱心網友回復:
我通常為每個專案設定虛擬主機,這對我來說是這樣的:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin [email protected]
DocumentRoot /var/www/html/example.com/public
<Directory "/var/www/html/example.com/public">
AllowOverride All
ReWriteEngine On
Options Indexes MultiViews FollowSymLinks
Order allow,deny
allow from all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
CustomLog ${APACHE_LOG_DIR}/example.com.log combined
這適用于我所有的 laravel 應用程式
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/445099.html
標籤:php 拉拉维尔 阿帕奇 ubuntu-20.04 laravel-9
