与Nginx合作的Laravel路线问题

与Nginx合作的Laravel路线问题,laravel,nginx,Laravel,Nginx,我已将我的Laravel应用程序文件放入/var/www/html/api/v2目录 我的nginx conf如下所示: listen 80 default_server; root /var/www/html; index index.php index.html index.htm index.nginx-de$ location / {

我已将我的Laravel应用程序文件放入
/var/www/html/api/v2
目录

我的nginx conf如下所示:

    listen                    80 default_server;
    root                      /var/www/html;
    index                     index.php index.html index.htm index.nginx-de$

    location / {
            try_files                $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
            try_files                $uri =404;
            fastcgi_split_path_info  ^(.+\.php)(/.+)$;
            fastcgi_pass             unix:/var/run/php/php7.2-fpm.sock;
            fastcgi_index            index.php;
            include                  fastcgi_params;
            fastcgi_param            SCRIPT_FILENAME $document_root$fastcgi$
            fastcgi_param            PATH_INFO $fastcgi_path_info;
    }
我想这样访问我的路由:
[host]/api/v2/[route]

但除了主页,它现在正在抛出404

请告诉我这里可能有什么问题。

更改此行

root   /var/www/html;

然后重新启动nginx

$ sudo systemctl restart nginx

您添加了服务器名称吗?@TuranZamanlı否,我正在侦听指令中使用默认服务器捕获所有内容。实际上,我希望像这样访问我的路由:[host]/api/v2/[route]。使用您的解决方案,它将仅在[host]中打开。此答案是正确的。
public/
dir应该始终是您的docroot,否则您的代码(包括带有密码和密钥的
.env
等)将对世界可见。如果完成后需要某个特定的路由前缀,请在路由中设置它。不要将磁盘上文件的物理布局(您不应该更改)与您可以在应用程序中创建的“虚拟”URL混淆。
$ sudo systemctl restart nginx