Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.
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;
  }
}

I'm trying to get nginx to serve any physical file (css, images, js) without doing anything to it put let php handle all other requests. Everything that is not a physical file should be passed to php.

But it's not working, php is being executed, but calling a .css file is also passed to php as a request.

[Update] I tried loading the css file directly in the browser www.site.dk/css/file.css.

share|improve this question
    
how are you referencing your css in your html and also where is it located on the filesystem? –  Mike Nov 3 '11 at 14:09
add comment

1 Answer 1

up vote 0 down vote accepted
server {
    server_name www.site.dk; #Default is port 80
    root /var/www/www.site.dk/webroot; #Use a webroot!

    access_log /var/www/www.site.dk/logs/access.log;
    error_log /var/www/www.site.dk/logs/error.log;

    location / {
            # This is cool because no php is touched for static content
            try_files $uri @use_php;
    }

    location @use_php {
            #The following line may have to be modified for desired behavior
            rewrite ^/(.+)$ /index.php last;
    }

    location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_intercept_errors on;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
    }
}

Some stuff from http://wiki.nginx.org/Drupal.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.