2013-12-15 58 views
1

我想在nginx上運行Laravel4.1。它在localhost上工作正常:8080 /但是當我到localhost:8080 /例如,我得到404 Not Found Error。這是我的nginx的配置:Laravel 4.1配置nginx在小牛

http { 

     server { 
      listen  8080; 
      server_name localhost; 

      #charset koi8-r; 

      #access_log logs/host.access.log main; 

      location/{ 
       root /var/www/html/example/public; 
       index index.php; 
      } 

      #error_page 404    /404.html; 

      # redirect server error pages to the static page /50x.html 
      # 
      error_page 500 502 503 504 /50x.html; 
      location = /50x.html { 
       root html; 
      } 

      # proxy the PHP scripts to Apache listening on 127.0.0.1:80 
      # 
      #location ~ \.php$ { 
      # proxy_pass http://127.0.0.1; 
      #} 

      # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
      # 
      location ~ \.php$ { 
       root   /var/www/html/example/public; 
       fastcgi_pass 127.0.0.1:9000; 
       fastcgi_index index.php; 
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
       include  fastcgi_params; 
      } 

     } 
} 

這是我的Laravel代碼:

Route::get('example', function() 
{ 
    return View::make('example'); 
}); 

回答

1

您可能需要添加重寫,所以任何URL被髮送回前端控制器...

# Removes trailing slashes 
if (!-d $request_filename) { 
    rewrite ^/(.+)/$ /$1 permanent; 
} 

# Rewrite to index.php unless the request is for an existing file (image, js, css, etc.) 
if (!-e $request_filename) { 
    rewrite ^/(.*)$ /index.php?/$1 last; 
    break; 
}