2011-11-03 79 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; 
     ... 
    } 
}