我在 xampp/htdocs 中安裝了我的 Laravel 9。當我將 API URL 與 localhost 一起使用時它作業正常,但當我使用設備的 IP 地址時它會拋出 404。
http://localhost/myapp/public/api/users它作業正常并將所有用戶回傳給我
但
http://192.168.254.6/myapp/public/api/users給我 404。因此,我也無法從本地網路訪問該應用程式。
我只是用一個 php 檔案測驗了這個案例test.php并且http://192.168.254.6/testapp/test.php作業正常。
我在 Laravel 公共目錄中的 index.php 中記錄了傳入的請求,我發現 Laravel 正在接收請求,但是當我嘗試在控制器甚至中間件中記錄請求時,我什么也沒得到。
可能是什么原因?
uj5u.com熱心網友回復:
經過長時間的研究,我找到了解決方案。該問題是由于https://tenancyforlaravel.com/config/tenancy.php的包組態檔造成的
舊的配置是:
/**
* The list of domains hosting your central app.
*
* Only relevant if you're using the domain or subdomain identification middleware.
*/
'central_domains' => [
'127.0.0.1',
'localhost',
],
添加特定的本地 IP 或空白字串可解決此問題:
/**
* The list of domains hosting your central app.
*
* Only relevant if you're using the domain or subdomain identification middleware.
*/
'central_domains' => [
'127.0.0.1',
'localhost',
''
],
如代碼注釋中所述,此配置應該僅在使用域或子域時有效,但我使用請求資料來識別租戶,但它仍然導致了問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/456038.html
