cecilli0n
cecilli0n

Reputation: 467

Laravel routes not working correctly

I have extracted the laravel.phar contents into c:\www\laravel correctly.

I have two problems which I believe are related.

1)

    Route::get('/testdir', function()
    {
        return 'Working';
    });

The Routes seem to be partially working because if I setup are route like 2) below and visit localhost/laravel/public/ I will see "Base test" correctly.

2)

    Route::get('/', function()
    {
        return 'Base test';
    });

My enviroment specifics

Nginx.Conf file setup

http {

include       mime.types;
default_type  application/octet-stream;

sendfile        on;

keepalive_timeout  65;


server {
    listen       80;
    server_name  localhost;

    location / {
        root   C:/www;
        index  index.php index.html index.htm;
    }

    location ~ \.php$ {
        root           C:/www;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $request_filename;
        include        fastcgi_params;
    }
}

Upvotes: 0

Views: 1048

Answers (1)

VF_
VF_

Reputation: 2653

You have to update your nginx config to match the public folder of your laravel installation.

Here's a sample to get you started:

http {

    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;


server {
    listen       80;
    server_name  localhost;
    root   C:/www/;

    location / {
        index  index.php index.html index.htm;
    }

    location /laravel/ {
        root   C:/www/laravel/public/;
        index  index.php index.html index.htm;
        try_files $uri $uri/ /index.php?$query_string;

        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $request_filename;
            include        fastcgi_params;
        }
    }

    location ~ \.php$ {
        root           C:/www/;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $request_filename;
        include        fastcgi_params;
    }
}

Make sure to restart nginx after you have made changes to the config!

Update:

Since we now defined C:/www on the server level, everything will be served according to the config made at server level. `location /laravel/ overrides this with its own block. All scripts not located under /laravel/ will work as before...

Upvotes: 1

Related Questions