2012-01-13 25 views
18

Tôi đang cố gắng thiết lập Khuôn khổ PHP Laravel để làm việc với Nginx. Dưới đây là cấu trúc thư mục của tôi:Thiết lập Laravel với Nginx

/project 
    /application 
    /laravel 
    /public 
     index.php 
    /legacy 
     /index.php 
     /stylesheets 
     default.css 

Về cơ bản những gì tôi có là một tiêu chuẩn Laravel tải w/một thư mục legacy ném trong đó chứa tất cả các tập tin từ dự án MVC phi của tôi.

Tôi cần Nginx kiểm tra trước nếu trang/tệp được yêu cầu tồn tại bên trong di sản, nếu có thì tôi muốn sử dụng. Nếu không, tôi muốn dự phòng tập tin index.php của Laravel nằm ở project/public/.

Tôi không có chuyên gia khi nói đến cấu hình Nginx nên bất kỳ trợ giúp nào bạn có thể cung cấp sẽ được đánh giá cao nhất.

+0

Đây không phải là Laravel nhưng hướng dẫn này sẽ hướng bạn đi đúng hướng: https://nealpoole.com/blog/2011/04/setting-up-php-fastcgi-and-nginx-dont- trust-the-tutorials-check-your-configuration / – mikelbring

Trả lời

20
server { 
    server_name .laravel.dev; 
    root /home/tamer/code/laravel/public; 

    index index.php index.html; 

    #browse folders if no index file 
     autoindex on; 

    # serve static files directly 
    location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ { 
     access_log off; 
     expires max; 
    } 

    # removes trailing slashes (prevents SEO duplicate content issues) 
    if (!-d $request_filename) 
    { 
     rewrite ^/(.+)/$ /$1 permanent; 
    } 

    # enforce NO www 
    if ($host ~* ^www\.(.*)) 
    { 
     set $host_without_www $1; 
     rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent; 
    } 


    # canonicalize codeigniter url end points 
    # if your default controller is something other than "welcome" you should change the following 
    if ($request_uri ~* ^(/lobby(/index)?|/index(.php)?)/?$) 
    { 
     rewrite ^(.*)$/permanent; 
    } 

    # removes trailing "index" from all controllers 
    if ($request_uri ~* index/?$) 
    { 
     rewrite ^/(.*)/index/?$ /$1 permanent; 
    } 

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

    # catch all 
    error_page 404 /index.php; 

     location ~ \.php$ { 
     try_files $uri =404; 
       fastcgi_pass unix:/tmp/php.socket; 
       fastcgi_index index.php; 
       #include fastcgi_params; 
       include /home/tamer/code/nginx/fastcgi_params; 
     } 
     access_log /home/tamer/code/laravel/storage/logs.access.log; 
     error_log /home/tamer/code/laravel/storage/logs.error.log; 
} 
Các vấn đề liên quan