2011-11-03 114 views
0
server { 
    listen 80; 
    server_name www.site.dk; 
    access_log /var/www/www.site.dk/logs/access.log; 
    error_log /var/www/www.site.dk/logs/error.log; 

    root /var/www/www.site.dk/; 


    location/{ 

    index index.php index.html; 

    if (-f $request_filename) { 
     break; 
    } 

    if (!-f $request_filename) { 
     rewrite ^/(.+)$ /index.php last; 
     break; 
    } 
    } 

    location ~ \.php$ { 
    include /etc/nginx/fastcgi_params; 
    fastcgi_pass 127.0.0.1:9000; 
    fastcgi_index index.php; 
    fastcgi_param SCRIPT_FILENAME /var/www/www.site.dk$fastcgi_script_name; 
    } 
} 

我想讓nginx服務任何物理文件(CSS,圖像,JS)沒有做任何事情,讓讓PHP處理所有其他請求。所有不是物理文件的應該傳遞給php。nginx的虛擬主機沒有提供靜態文件

但它不工作,php正在執行,但調用.css文件也作爲請求傳遞給php。

+0

更好地衝着serverfault.com我認爲... –

回答

0

這將做的工作

server { 
    listen 80; 
    server_name www.site.dk; 
    access_log /var/www/www.site.dk/logs/access.log; 
    error_log /var/www/www.site.dk/logs/error.log; 

    root /var/www/www.site.dk/; 
    index index.php index.html; 

    location/{ 
     try_files $uri $uri/ @fastcgi; 
    } 

    location ~ .+\.php$ { 
     location ~ \..*/.*\.php$ { return 400; } 
     error_page 418 = @fastcgi; 
     return 418; 
    } 

    location @fastcgi { 
     include /etc/nginx/fastcgi_params; 
     fastcgi_pass 127.0.0.1:9000; 
     ... 
    } 
}