Nginx上的Laravel API Route 404

1wnzp6jl  于 2023-06-30  发布在  Nginx
关注(0)|答案(1)|浏览(150)

我在Azure App Service上部署了一个laravel 8应用程序,这是我的nginx配置:

server {
    listen 8080;
    listen [::]:8080;
    root /home/site/wwwroot/public; # changed for Laravel
    index  index.php index.html index.htm;
    server_name doctors-portal-api.azurewebsites.net;

    location / {            
        try_files $uri $uri/ /index.php?$args; # changed for Laravel
    }

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /html/;
    }
    
    # Disable .git directory
    location ~ /\.git {
        deny all;
        access_log off;
        log_not_found off;
    }

    # Add locations of phpmyadmin here.
    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
        fastcgi_pass 127.0.0.1:9000;
        include fastcgi_params;
        fastcgi_param HTTP_PROXY "";
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param QUERY_STRING $query_string;
        fastcgi_intercept_errors on;
        fastcgi_connect_timeout         300; 
        fastcgi_send_timeout           3600; 
        fastcgi_read_timeout           3600;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
    }
}

这是我的routes_public.php文件:

<?php

use App\Api\Doctor\DoctorApiController;

Route::post('doctors/register', [DoctorApiController::class, 'register'])->name('doctors.register');
Route::get('doctors/hospitals', [DoctorApiController::class, 'hospitals'])->name('doctors.hospitals');
Route::get('doctors/{md_id}', [DoctorApiController::class, 'show'])->name('doctors.show');
Route::get('doctors/user/{user_id}', [DoctorApiController::class, 'show_by_user_id'])->name('doctors.show_by_user_id');
Route::get('doctors', [DoctorApiController::class, 'index'])->name('doctors.index');

有了这个设置,我可以毫无问题地访问这些API路由:
https://doctors-portal-api.azurewebsites.net/api/v1/doctors
https://doctors-portal-api.azurewebsites.net/api/v1/files
但是,下面的API路由给予了一个错误:404 Not Found
https://doctors-portal-api.azurewebsites.net/api/v1/doctors/hospitals
https://doctors-portal-api.azurewebsites.net/api/v1/file/upload
我需要做什么来修复它?

当我在本地运行laravel应用程序时,所有API URL在localhost上都能正常工作。

jgovgodb

jgovgodb1#

几个小时前我也遇到了同样的问题。我的laravel 10应用程序按预期工作,突然停止工作(我没有部署新版本)。
我意识到nginx版本改为1.24,所以你可以检查这部分。
对我有用的是在/etc/nginx/sites-enabled中使用与/etc/nginx/sites-enabled中相同的配置文件
您可以尝试像这样复制此文件:

cp /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default

考虑到默认值是你提到的配置文件名。
如果你愿意,你也可以做一个符号链接

ln -s sites-available/default sites-enabled/default

您可能必须删除sites-enabled/default才能进行链接
希望这对你有用

相关问题