2017-07-28 178 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命令这对你的工作!