Laravel路由导致实时服务器上的404错误

问题描述

我在本地主机上开发了一个laravel应用程序,并且运行正常。我正在尝试在Ubuntu 20.04上使用nginx将其部署到AWS Lightsail实例上。我已经上传了laravel应用,并将nginx根目录更改为laravelapp / public。

主索引页面(着陆页)工作正常,但我的所有路由均不工作(即/ login,/ about等)。当我尝试访问任何一条路线时,都收到404 not found错误。

这是我的Nginx / sites_available /默认文件:

# Default server configuration
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/investa/public;

    index index.php index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        # First attempt to serve request as file,then
        # as directory,then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;

        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    }

}

这是我的路线列表的视图:

Laravel App Routes

解决方法

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

在这里比较:https://laravel.com/docs/7.x/deployment#nginx

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...