【发布时间】:2021-12-18 05:04:09
【问题描述】:
我在同一台服务器上有一个带有 Laravel API 的 Nuxt 应用程序,我遇到了一种情况,即 nginx 正在使用 /api/api 复制 /api,因为我使用的是 laravel api.php。
这是我的设置。我在sites-available 下有一个简单的conf,在sites-enable 的半链接上可用。
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;
}
有什么想法我可能做错了吗?
理想情况下,我想为 laravel 路由到 /api
http://example.com/api/login/google
现在,如果我在下面有这个,它似乎可以工作。
http://example.com/api/api/login/google
api.php 示例
//通过google登录方式登录。
Route::get('login/google', [GoogleAuthController::class, 'redirect']);
Route::get('login/google/callback', [GoogleAuthController::class, 'callback']);
【问题讨论】:
-
你能显示你的api路由文件吗?
-
@Aless55 当然,我用路线示例更新了我的问题。
-
默认的 laravel 配置是在 api 路由前加上 api。 AFAIK,您可以在
RouteServiceProvider中更改此设置 -
@apokryfos 这就是问题所在。作者可以更改他们的 nginx 配置文件或 RouteServiceProvider 中的方法。你的情况真的有必要使用 nginx 配置吗?
-
@apokryfos 知道在 nginx 配置中处理它的方法吗?如果可能的话,宁愿在那里处理它
标签: php laravel ubuntu nginx nuxt.js