2014-01-13 13 views
11

nginxを使用してLaravel 4プロジェクトをセットアップしようとしています。ラージベル4のnginx設定

server { 
     listen 80; 

     root /home/prism/www/laravel/public; 
     index index.php index.html index.htm; 

     server_name example.com; 

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

     } 
       location ~ \.php$ { 

       try_files $uri =404; 
       fastcgi_pass unix:/var/run/php5-fpm.sock; 
       fastcgi_index index.php; 
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
       include fastcgi_params; 
     } 

しかし、私の問題は、デフォルトのインストールに付属しているデフォルトのものを除くすべての他のルートのためのその示す「404見つかりません」というエラーである:ここではlaravelのための私のnginxのサーバーのブロックです。

答えて

25

これは動作するLaravel 4とLaravel 4.1で使用したNGINX設定です。

server { 

    listen 80; 
    server_name sub.domain.com; 
    set $root_path '/var/www/html/application_name/public'; 
    root $root_path; 

    index index.php index.html index.htm; 

    try_files $uri $uri/ @rewrite; 

    location @rewrite { 
     rewrite ^/(.*)$ /index.php?_url=/$1; 
    } 

    location ~ \.php { 

     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_index /index.php; 

     include /etc/nginx/fastcgi_params; 

     fastcgi_split_path_info  ^(.+\.php)(/.+)$; 
     fastcgi_param PATH_INFO  $fastcgi_path_info; 
     fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    } 

    location ~* ^/(css|img|js|flv|swf|download)/(.+)$ { 
     root $root_path; 
    } 

    location ~ /\.ht { 
     deny all; 
    } 

} 
+1

これは私のために働いたが、あなたの設定のすべてを使うことはできませんでした。私がしたことは、Nginxの現在のデフォルトを使って 'location/{}'の 'try_files'を自分のものに変更してから、' @rewrite'の場所を追加することでした。今はすべてが素敵です。 –

+0

いいえhttp://wiki.nginx.org/Pitfalls#Taxing_Rewrites @RobGordijnははるかに良い解決策を持っています。 –

12

あなたは/ {...}

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

の$ QUERY_STRINGが私のために働いていた場所のためにこれを試みることができます。

+0

私は/ workの下でこれを設定しています:try_files $ uri $ uri//index.php?$args; –