Nginx+Pressflow Config

Events happening in the community are now at Drupal community events on www.drupal.org.
MTecknology's picture

I'm using this for configuration of Nginx and Pressflow. I was wondering if anyone sees any obvious issues in it. If not, then I'm happy to share something that many others can use.

michael@insto:/etc/nginx$ cat conf.d/profarius.com.conf

server {
  server_name profarius.com;
  include templates/pressflow;
}

michael@insto:/etc/nginx$ cat templates/pressflow

root /home/$server_name/pressflow;

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

location ~ \.php$ {
  include fastcgi_params;
  fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
  fastcgi_pass   unix:/tmp/phpcgi-$server_name.socket;
  track_uploads proxied 30s;
}

location @pressflow {
  rewrite ^(.*)$ /index.php?q=$1 last;
  include fastcgi_params;
  fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
  fastcgi_pass   unix:/tmp/phpcgi-$server_name.socket;
  track_uploads proxied 30s;
}

location ^~ /progress {
  report_uploads proxied;
}

include templates/drop;

Comments

I'm unsure why the fastcgi

brianmercer's picture

I'm unsure why the fastcgi parameters would be necessary in the @pressflow block.

I'd add a

try_files $uri @pressflow;

to the .php block so people don't get an ugly error if they go to nonexistentfile.php, and to address a nasty security hole caused by cgi_pathinfo=1.

I usually have to do

rewrite ^/(.*)$ /index.php?q=$1 last;

so that the leading slash is stripped from the query string or it causes problems like this: http://drupal.org/index.php?q=/

If you've gotten nginx upload progress to show for core uploads and don't mind sharing your work to, I'd be very interested in seeing that. Thanks.

I Wish

MTecknology's picture

Oh how I wish I got the upload progress working. I'm still fighting that.

Thanks for the pointer on cgi_pathinfo. That regex does indeed make sense. :)

Michael Lustfield
Ubuntu Member, Nginx Hacker

There is a solution now for

brianmercer's picture

There is a solution now for upload progress with filefield.

http://drupal.org/project/filefield_nginx_progress

Brian's got it right :)

mike503's picture

I posted about the same thing, trying to get a fix in place.
http://drupal.org/node/827236

Please, help me! I use Nginx

Terko's picture

Please, help me!
I use Nginx and Pressflow and I just noticed, that the pages with pagination (example: example.com/funny_pics?page=0,1) don't work.
I've enabled the option in Boost to cache url with variables and I can see them in the cache folder. But drupal don't serve them. Drupal serve only nodes without ?page=
My config is:

  location / {
    try_files $uri @cache;
  }

  # This will try to see if we have a boost file in place. no harm done if this is not used
  location @cache {
    # queries, drupal cookies, or not GET methods, all require PHP processing.
    if ($query_string ~ ".+") {
      return 405;
    }
    if ($http_cookie ~ "DRUPAL_UID" ) {
      return 405;
    }
    if ($request_method !~ ^(GET|HEAD)$ ) {
      return 405;
    }
    error_page 405 = @drupal;

    # Drupal uses 1978 - I am 4 years older than Dries :)
    add_header Expires "Tue, 22 Sep 1974 08:00:00 GMT";      
    add_header Cache-Control "must-revalidate, post-check=0, pre-check=0";
    try_files /cache/normal/$host${uri}$args.html /cache/$host${uri}$args.html  @drupal;
  }

It looks like you're missing

brianmercer's picture

It looks like you're missing the underscores. Do the files in your cache folder have the underscores in place of the "?" (Unless you've changed that character to something else in Boost settings.)

Try this:

try_files /cache/normal/$host${uri}_$args.html /cache/$host${uri}_$args.html  @drupal;

There was underscores, but

Terko's picture

There was underscores, but maybe they was stripped when pasted. Do you have underscores in this example too?

You're right, that's just the

brianmercer's picture

You're right, that's just the drupal.org filter.

Hmm...it should work. My site serves the pages from the Boost cache: http://test.brianmercer.com/?page=1 has the Boost comment on the bottom.

I did have to clear the

brianmercer's picture

I did have to clear the browser cache after visiting the ?page=1 for the first time. Otherwise I'm the first visitor and get the live page and refreshing only does a 304 Not Modified and doesn't load the Boost page on a refresh.

Hmm, everything must be fine,

Terko's picture

Hmm, everything must be fine, but it's not :( I don't know why. It's with underscores, it serve cached content without variables, but when variables, they simply are not served.

Maybe I didn't compiled Nginx

Terko's picture

Maybe I didn't compiled Nginx with support of $args? Maybe this is the reason?

Impossible, I think. So

brianmercer's picture

Impossible, I think.

So you've confirmed that files like these exist in the cache/normal/example.com/ folder:

_page=1.html
_page=1.html.gz

Can you link a public page here?

The next thing to do is to use a version of nginx with debugging, add your IP to debug_connection and read the output at error.log and see why the regex isn't matching.

My public page is

Terko's picture

My public page is http://uhaaa.com
You can try some articles with their first page. It's cached.
if you go to second - no cached.
The cache is in folder normal/uhaaa.com
So if I try to access the cached file, for example :
http://uhaaa.com/cache/normal/uhaaa.com/krasavici_page=0,1.html i can open it. So it's there. But only http://uhaaa.com/krasavici is cached :(

Doh, just reread your post.

brianmercer's picture

Doh, just reread your post. You have this:

    # queries, drupal cookies, or not GET methods, all require PHP processing.
    if ($query_string ~ ".+") {
      return 405;
    }

which bypasses the cache on any query string. I don't use that and I'm not sure why he included that. No doubt, something wasn't working for him without it, but I don't know what. My sites work fine without that.

Remove that and see how it goes. Maybe Yhager will post what module or config made that necessary.

Wooooorrrrrkkkkssss!!! :)

Terko's picture

Wooooorrrrrkkkkssss!!! :) Hehe, thank you!!! :) I didn't noticed this code. Now everything is fine :)

Nginx

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: