我在同一臺服務器上有一個帶有 Laravel API 的 Nuxt 應用程式,我遇到了這樣一種情況:由于我使用的是 laravel api.php,因此 nginx 正在將 /api 與 /api/api 復制。
這是我的設定。我在sites-available下只有一個簡單的conf,位于啟用站點的半鏈接上。
server {
listen 80;
root /var/www/html/nuxt-apt-front/dist;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name example.com;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location /api{
alias "/var/www/html/laravel-api/public";
try_files $uri $uri/ @api;
location ~ \.php$ {
fastcgi_split_path_info ^(. \.php)(/. )$;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/html/laravel-api/public/index.php;
}
}
location @api {
rewrite /api/(.*)$ /api/index.php?/$1 last;
}
include /etc/nginx/sites-available/*.conf;
}
任何想法我可能做錯了什么?
理想情況下,我想路由到 /api for laravel
http://example.com/api/login/google
現在,如果我在下面有這個,它似乎可以作業。
http://example.com/api/api/login/google
api.php 示例
// 通過谷歌登錄登錄。
Route::get('login/google', [GoogleAuthController::class, 'redirect']);
Route::get('login/google/callback', [GoogleAuthController::class, 'callback']);
uj5u.com熱心網友回復:
如上所述,如果您想保持 Nginx 檔案原樣,請在您的RouteServiceProvider.
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
對此:
Route::middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
這有點自我解釋,前綴被添加到每個 api 路由/呼叫。通過洗掉它,它被簡單地遺漏了,只有你的 Nginx 配置附加了一個。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/347327.html
下一篇:Haskell-GHC錯誤:找不到模塊“Prelude”/也許您還沒有安裝包“base-4.12.0.0”的分析庫?
