Nginx | Can only access some routes but not all

Published 1 week ago by Kazuto

Hey guys,

I can access routes like "manage/users" or "manage/roles" but not "manage/downloads". Locally everything works just fine, so it has to so something with my server.

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

        root /var/www/path/to/my/project/public;

        index index.php index.html index.htm;

        server_name MYDOMAIN;

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

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

        location ~ /\.ht {
                deny all;
        }

        location ~ /.well-known {
                allow all;
        }
}
Best Answer (As Selected By Kazuto)
Kazuto

I should have look in the logs sooner.

I've forgot that I've added soft deletes locally but have not migrated them to the production server.

Now everything works fine.

Thanks @Snapey

neilherbertuk

Hi KAZUTO,

It would be helpful if you could provide more detail to allow someone to be able to answer your question. Please check out Laracasts Posting Guidelines which details what makes a good post and the sort of information needed to be able to help answer you.

Please can you post your routes file, the server os and the os of your local environment, what version of nginx, what version of PHP and what version of Laravel you are using.

Neil

Kazuto

Server OS: Ubuntu 16.04 | PHP 7.0 | nginx: 1.10.3

Local OS: OSX 10.12.1 | PHP 7.1.4

Laravel: 5.4.32

Routes:

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

Auth::routes();

Route::prefix('manage')->middleware('role:superadministrator|administrator|editor|author|contributor')->group(function () {
    Route::get('/', 'ManageController@index');
    Route::get('/dashboard', 'ManageController@dashboard')->name('manage.dashboard');

    /* General */
    Route::resource('/posts', 'PostController');
    Route::post('/posts/{post}/restore', 'PostController@restore')->name('posts.restore');
    Route::delete('/posts/{post}/delete', 'PostController@delete')->name('posts.delete');

    Route::resource('/downloads', 'DownloadController');
    Route::post('/downloads/{download}/restore', 'DownloadController@restore')->name('downloads.restore');
    Route::delete('/downloads/{download}/delete', 'DownloadController@delete')->name('downloads.delete');

    Route::resource('/streams', 'StreamController');
    Route::post('/streams/{stream}/restore', 'StreamController@restore')->name('streams.restore');
    Route::delete('/streams/{stream}/delete', 'StreamController@delete')->name('streams.delete');

    Route::resource('/providers', 'ProviderController');
    Route::post('/providers/{provider}/restore', 'ProviderController@restore')->name('providers.restore');
    Route::delete('/providers/{provider}/delete', 'ProviderController@delete')->name('providers.delete');

    /* eSport */
    Route::resource('/teams', 'TeamController');
    Route::post('/teams/{team}/restore', 'TeamController@restore')->name('teams.restore');
    Route::delete('/teams/{team}/delete', 'TeamController@delete')->name('teams.delete');

    Route::resource('/members', 'MemberController');
    Route::post('/members/{member}/restore', 'MemberController@restore')->name('members.restore');
    Route::delete('/members/{member}/delete', 'MemberController@delete')->name('members.delete');

    Route::resource('/awards', 'AwardController');
    Route::post('/awards/{award}/restore', 'AwardController@restore')->name('awards.restore');
    Route::delete('/awards/{award}/delete', 'AwardController@delete')->name('awards.delete');

    Route::resource('/matches', 'MatchController');
    Route::post('/matches/{match}/restore', 'MatchController@restore')->name('matches.restore');
    Route::delete('/matches/{match}/delete', 'MatchController@delete')->name('matches.delete');

    Route::resource('/games', 'GameController');
    Route::post('/games/{game}/restore', 'GameController@restore')->name('games.restore');
    Route::delete('/games/{game}/delete', 'GameController@delete')->name('games.delete');

    Route::resource('/sponsors', 'SponsorController');
    Route::post('/sponsors/{sponsor}/restore', 'SponsorController@restore')->name('sponsors.restore');
    Route::delete('/sponsors/{sponsor}/delete', 'SponsorController@delete')->name('sponsors.delete');


    Route::resource('/users', 'UserController');
    Route::resource('/permissions', 'PermissionController');
    Route::resource('/roles', 'RoleController');
    Route::resource('/menus', 'MenuController');
});

Route::get('/home', 'HomeController@index')->name('home');
Snapey
Snapey
6 days ago (618,385 XP)

something must happen? an error? what?

Cronix
Cronix
6 days ago (148,700 XP)

If you have extra methods in a resource controller beyond the default ones (index/create/store/show/edit/update/destroy), those routes need to go above the Route::resource route. All of yours are backwards with the Route:resource() first and the extra routes after.

https://laravel.com/docs/5.5/controllers#resource-controllers

If you need to add additional routes to a resource controller beyond the default set of resource routes, you should define those routes before your call to Route::resource; otherwise, the routes defined by the resource method may unintentionally take precedence over your supplemental routes:

Kazuto

@Snapey error_log shows no entries. I just get the regular "Whoops. Something went wrong."

access_log shows this:

XX.XX.XX.XX - - [16/Sep/2017:11:03:02 +0200] "GET /manage/members HTTP/1.1" 500 20837 "http://turtles.devel.kazuto.de/manage/dashboard" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.78 Safari/537.36"
XX.XX.XX.XX- - [16/Sep/2017:11:03:02 +0200] "GET /favicon.ico HTTP/1.1" 200 0 "http://turtles.devel.kazuto.de/manage/members" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.78 Safari/537.36"

Looking at this it seems to be a 500 error code.

@Cronix I've changed the order of the routes and put every ::resource to the end. But nothing has changed.

Snapey
Snapey
5 days ago (618,385 XP)

what about the laravel log file?

Kazuto

I should have look in the logs sooner.

I've forgot that I've added soft deletes locally but have not migrated them to the production server.

Now everything works fine.

Thanks @Snapey

Sign In or create a forum account to participate in this discussion.