2017-07-28 175 views
0

我只是用Laravel開始的最後幾天,我對URL路由問題,我http://localhost:8017/laravel看起來不錯,但http://localhost:8017/laravel/foo回報Laravel - 404未找到

404未找到

我的OS Ubuntu的16.04,Laravel 5.4

路由/ web.php

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

// oedin 
Route::get('foo', function() { 
    return 'Hello World'; 
}); 

nginx的配置

server { 
    listen 8017 default_server; 
    listen [::]:8017 default_server; 

    # SSL configuration 
    # 
    # listen 443 ssl default_server; 
    # listen [::]:443 ssl default_server; 
    # 
    # Note: You should disable gzip for SSL traffic. 
    # See: https://bugs.debian.org/773332 
    # 
    # Read up on ssl_ciphers to ensure a secure configuration. 
    # See: https://bugs.debian.org/765782 
    # 
    # Self signed certs generated by the ssl-cert package 
    # Don't use them in a production server! 
    # 
    # include snippets/snakeoil.conf; 

    #root /var/www/html; 
    root /home/oedin/webdev; 

    # Add index.php to the list if you are using PHP 
    index index.php index.html index.htm; 

    server_name localhost; 

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

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
    # 
    location ~ \.php$ { 
     include snippets/fastcgi-php.conf; 
     #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; 

    } 

    # deny access to .htaccess files, if Apache's document root 
    # concurs with nginx's one 
    # 
    #location ~ /\.ht { 
    # deny all; 
    #} 
} 
+0

當你點擊http:// localhost:8017/laravel時,哪個頁面打開? –

+0

Laravel歡迎頁面 – oedin

回答

0

東西,如果你想爲nginx的你的應用程序,它的建議,使其中包含你的項目的根文件夾一個新的nginx虛擬主機的配置。

然而,使用php artisan serve可以讓生活變得更容易,而且此時不需要nginx服務器。

+0

工作#php artisan serve' ..這是工作,如何使它http:// localhost: 8000/laravel/foo ..而不是http:// localhost:8000/foo – oedin

+0

您應該爲您的路由添加路由前綴https://laravel.com/docs/5.4/routing#route-group-prefixes –

+0

'nginx vhost'和'route prefix'做這個工作......感謝隊友 – oedin

1

如果追加的index.php它會工作,我想。

http://localhost:8017/laravel/index.php/foo 
+0

nope,..它不工作.. – oedin

+0

這很奇怪你在你的index.php文件在公共目錄下更改了什麼嗎? – Sletheren

+0

nope,只是在路線/ web.php – oedin

0

你可以試試這個:

Route::group(['namespace' => 'Laravel', 'prefix' => 'laravel', 'middleware' => 'laravel'], function() { 

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

    // oedin 
    Route::get('foo', function() { 
     return 'Hello World'; 
    }); 
}); 

你應該在終端

your URL like http://localhost:8000/laravel/foo 

希望運行php artisan SERV命令這對你的工作!