我在Nginx上运行的laravel应用程序上获得了404

时间:2017-07-12 04:55:42

标签: laravel nginx

我有这个nginx配置。

server {
        listen 80;
        listen [::]:80;

        server_name apps.myapp.com;

        root /var/www/apps.myapp.com/public;
        index index.php;

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

我有这条路线:

Route::get('/lead', 'LeadsController@index' );

当我访问http://apps.myapp.com/lead时,我得到404。

2 个答案:

答案 0 :(得分:0)

您可以运行nginx -t来检查文件配置中是否有任何错误,此外还需要添加fastcgi_pass

以下是我的生产服务器的nginx配置

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /var/www/laravel/public/;
    index index.php index.html index.htm;

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

     location ~ \.php$ {
         try_files $uri /index.php =404;
         fastcgi_split_path_info ^(.+\.php)(/.+)$;
         fastcgi_pass unix:/var/run/php5-fpm.sock;
         fastcgi_index index.php;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         include fastcgi_params;
     }
}

您可以阅读本教程非常有帮助: https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-in-ubuntu-16-04

答案 1 :(得分:0)

这是我用于Laravel应用程序的配置。

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

location ~ \.php$ {
                try_files $uri $uri/ /index.php?$query_string;
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
}