在Nginx上找不到Laravel路由 [英] Laravel routes not found on nginx

查看:393
本文介绍了在Nginx上找不到Laravel路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试访问测试应用程序时,只有索引路由有效: malte.italoborg.es

如果我尝试访问其他路线,例如: malte.italoborg.es/admin

我收到404错误.

我的nginx应用文件:

server {
    listen 80;
    server_name malte.italoborg.es;
    root /home/italo/www/malte.italoborg.es/public;

    charset utf-8;

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /home/log/nginx/malte.italoborg.es-error.log error;
    error_page 404 /index.php;
    sendfile off;

    # Point index to the Laravel front controller.
    index index.php;

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

    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;
    }

    location ~ /\.ht {
        #deny all;
    }
}

我在StackOverflow的另一个链接中尝试了此解决方案,但不适用于我.

在nginx上未找到"所有Laravel路由

我正在Digital Ocean中使用nginx.

:: UPDATE ::

我的routes.php

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

Route::get('/',
    ['as' => 'site.welcome.index', 'uses' => 'Site\WelcomeController@index']
);

Route::group(['prefix' => 'admin'], function () {

    // Login
    Route::get('login',
        ['as' => 'admin.auth.login', 'uses' => 'Admin\Auth\AuthController@getLogin']
    );
    Route::post('login',
        ['as' => 'admin.auth.login', 'uses' => 'Admin\Auth\AuthController@postLogin']
    );
    Route::get('logout',
        ['as' => 'admin.auth.logout', 'uses' => 'Admin\Auth\AuthController@getLogout']
    );

    // Password
    Route::get('password/email',
        ['as' => 'admin.password.email', 'uses' => 'Admin\Auth\PasswordController@getEmail']
    );
    Route::post('password/email',
        ['as' => 'admin.password.email', 'uses' => 'Admin\Auth\PasswordController@postEmail']
    );

    // Password reset
    Route::get('password/reset/{token}',
        ['as' => 'admin.password.reset', 'uses' => 'Admin\Auth\PasswordController@getReset']
    );
    Route::post('password/reset',
        ['as' => 'admin.password.reset', 'uses' => 'Admin\Auth\PasswordController@postReset']
    );

    Route::group(['middleware' => 'auth'], function () {

        // Home
        Route::get('/', ['as' => 'admin.home.index', 'uses' => 'Admin\HomeController@index']);

        // My Account
        Route::get('profile',
            ['as' => 'admin.profile.edit', 'uses' => 'Admin\ProfileController@edit']
        );

        Route::put('profile',
            ['as' => 'admin.profile.update', 'uses' => 'Admin\ProfileController@update']
        );

        // Nail polish
        Route::resource('polishes', 'Admin\NailPolishController');

        // Brands
        Route::resource('brands', 'Admin\BrandController');

        // Types
        Route::resource('types', 'Admin\TypeController');
    });
});

解决方案

请尝试更改此内容

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

对此

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

并删除此行:

try_files $uri /index.php =404;

when I try to access my test app, just the index route works: malte.italoborg.es

If I try to access another route, like: malte.italoborg.es/admin

I got 404 error.

My nginx app file:

server {
    listen 80;
    server_name malte.italoborg.es;
    root /home/italo/www/malte.italoborg.es/public;

    charset utf-8;

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /home/log/nginx/malte.italoborg.es-error.log error;
    error_page 404 /index.php;
    sendfile off;

    # Point index to the Laravel front controller.
    index index.php;

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

    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;
    }

    location ~ /\.ht {
        #deny all;
    }
}

I tried this solution in an another link in StackOverflow, but doesn't worked for me.

All Laravel routes "not found" on nginx

I'm using nginx in Digital Ocean.

::UPDATE::

My routes.php

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

Route::get('/',
    ['as' => 'site.welcome.index', 'uses' => 'Site\WelcomeController@index']
);

Route::group(['prefix' => 'admin'], function () {

    // Login
    Route::get('login',
        ['as' => 'admin.auth.login', 'uses' => 'Admin\Auth\AuthController@getLogin']
    );
    Route::post('login',
        ['as' => 'admin.auth.login', 'uses' => 'Admin\Auth\AuthController@postLogin']
    );
    Route::get('logout',
        ['as' => 'admin.auth.logout', 'uses' => 'Admin\Auth\AuthController@getLogout']
    );

    // Password
    Route::get('password/email',
        ['as' => 'admin.password.email', 'uses' => 'Admin\Auth\PasswordController@getEmail']
    );
    Route::post('password/email',
        ['as' => 'admin.password.email', 'uses' => 'Admin\Auth\PasswordController@postEmail']
    );

    // Password reset
    Route::get('password/reset/{token}',
        ['as' => 'admin.password.reset', 'uses' => 'Admin\Auth\PasswordController@getReset']
    );
    Route::post('password/reset',
        ['as' => 'admin.password.reset', 'uses' => 'Admin\Auth\PasswordController@postReset']
    );

    Route::group(['middleware' => 'auth'], function () {

        // Home
        Route::get('/', ['as' => 'admin.home.index', 'uses' => 'Admin\HomeController@index']);

        // My Account
        Route::get('profile',
            ['as' => 'admin.profile.edit', 'uses' => 'Admin\ProfileController@edit']
        );

        Route::put('profile',
            ['as' => 'admin.profile.update', 'uses' => 'Admin\ProfileController@update']
        );

        // Nail polish
        Route::resource('polishes', 'Admin\NailPolishController');

        // Brands
        Route::resource('brands', 'Admin\BrandController');

        // Types
        Route::resource('types', 'Admin\TypeController');
    });
});

解决方案

Please try changing this

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

to this

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

And also remove this line:

try_files $uri /index.php =404;

这篇关于在Nginx上找不到Laravel路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆