1 (edited by marrco 2011-01-24 04:26:39)

Topic: GS and NGINX

i'm using GetSimple with nginx and it's really fast. I tried to create a good config file, hope someone will improve this. At the moment i'm running 8 low traffic sites on a low end VPS using less than 100 MB ram, including exim4, php, and all modules i loaded. And all perform well even under heavy simulated traffic (loadimpact.com test).

My guess it that GetSimple CMS and Nginx together are the best and fastest thing you can use if you want a lot of speed on a budget server.

server {
  listen          80;
  server_name     *.mysite.com;
  rewrite ^       http://mysite.com$request_uri permanent;
 }

server {
    listen 80;
    server_name mysite.com;
    access_log off;
    root /var/www/www.mysite.com;
    index index.php;
    try_files       $uri $uri/ /index.php?id=$uri;

    location ~* \.php$ {
      include /etc/nginx/fastcgi_php;
      expires 2h;
    }

    location ~* \.(ico|js|gif|jpg|png)$ {
      try_files       $uri /index.php?id=$uri;
      expires 14d;
    }

    location ~* \.(css|htm|html)$ {
      try_files       $uri /index.php?id=$uri;
      expires 2d;
    }

}

Re: GS and NGINX

Hi Marrco,

I am new to both GetSimple and to configuring Nginx (I have been using it for several months now following the basic setup found at http://library.linode.com )

I like your use of the try_files directive, which is very efficient if the entire site is based on GS.  Instead of that approach I ported the Apache rewrite rules to:

         if (!-e $request_filename){
              rewrite ^(/[A-Za-z0-9\-]+)?/([A-Za-z0-9\-]+)/?$ /index.php?id=$2 last;
            }

Here

^(/[A-Za-z0-9\-]+)?

matches the parent page if any, and

              /?$

supports slugs with or without a trailing / .  I didn't want a regexp in the rewrite rule so general that it would match content in other (non-GetSimple) subdirectories on the site,  including DokuWiki.

I agree with all your positive comments about Nginx.  When I am more comfortable with its configuration files I'll migrate all my sites (hosted on various inexpensive VPSs) to it.  I have been using Cherokee but had some problems with version upgrades and decided the user-friendly management interface wasn't worth it.

Regards,
Bill

Re: GS and NGINX

Hi BillF,
try_files is more efficient, one more reason to chose nginx over apache, but it is not supported on old builds.

I think my config has 2 problems:
-) still missing newer .htaccess rules (i think there's something to deny access to xml files but /sitemap.xml and maybe a few others)
-) 404 for mysite.com/notexistent.php

so i'm waiting to test 3.0 final to add the newer rules and post this as a WIKI.

i think nginx is the best companion for a light and fast cms like GetSimple

Re: GS and NGINX

I'm using this code

        location / {
                try_files $uri $uri/ /index.php?id=$uri;
        }

and it works well with the %slug% structure. if I use %parent/%slug% it throws me a 404 error for all child pages.

Any ideas? Thanks.

5 (edited by marrco 2012-03-19 06:07:30)

Re: GS and NGINX

here a slightly better version. Includes fastcgi caching and more security.

server {
  listen          80;
  server_name     *.mysite.org *.mysite.com;
  rewrite ^       http://mysite.org$request_uri permanent;
 }

server {
        listen 80;
        server_name mysite.org;
        charset utf-8;
        access_log off;
        root /var/www/mysite.org;
        index index.php;

        location / {
        try_files       $uri $uri/ /index.php?id=$uri&$args;
        }

        location ~* \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_index index.php;
        try_files $uri =404;
        fastcgi_pass unix:/var/run/www/php.sock;
                # define in /etc/nginx/nginx.conf
                # fastcgi_cache_path  /var/cache/nginx  levels=1:2 keys_zone=GETSIMPLE:10m inactive=15m;
        fastcgi_cache GETSIMPLE;
          fastcgi_cache_key "$scheme$request_method$host$request_uri";
          fastcgi_cache_valid  200 302  100m;
          fastcgi_cache_valid  404      10m;
          expires 2h;
        }

       location ^~ /admin/ {
                try_files $uri /admin/index.php?id=$uri&$args;
                include /etc/nginx/fastcgi_params;
                fastcgi_index index.php;
                fastcgi_pass unix:/var/run/www/php.sock;
       }

        location ~* \.(?:ico|js|gif|jpg|png)$ {
          expires 14d;
        }

        location ~* \.(htm|css|html)$ {
          expires 2d;
        }

# this blocks direct access to the XML files (but sitemap.xml) - they hold all the data
        location ~* \.xml$           { deny all; }
        location = /sitemap.xml { allow all; }


# this prevents hidden files (beginning with a period) from being served
        location ~ /\.          { deny all; }

        location ^~ /uploads/ {
        if ($request_uri ~* \.php$) {return 403;}
        }
}

Re: GS and NGINX

Hello marrco, thanks for posting that pesky configuration!

There is , however, a slight problem with it: it does not serve the javascripts for the admin section.
I get an "access denied" message ...

What I did was to copy the exact config file as you posted it, modify the server name and also replace the line

fastcgi_pass unix:/var/run/www/php.sock;

with

fastcgi_pass   127.0.0.1:9000;

since I use php 5 fmp modules.

Would you have an idea of what's wrong here?

Thanks in advance!

Re: GS and NGINX

@softexpert, i just updated that config (it was missing an explicit allow for sitemap.xml) but it should work fine. No idea about your error. Try to comment out the fcgi cache part, or start testing with the first config i posted (mind that's insecure!). Most options i'm using are for NGINX version 1 or newer with php 5.3.x and have been tested only on debian squeeze with nginx installed via backports (that's adding to your

/etc/apt/sources.list

a line with

deb http://backports.debian.org/debian-backports squeeze-backports main contrib non-free

and (re)installing nginx via

apt-get -t squeeze-backports install nginx

)
what's the exact error you're receiving?

Re: GS and NGINX

@marrco

Since you seem to have tinkered with the nginx setup quite a lot, would you know what the rewrite
rules are for the News Manager Plugin http://get-simple.info/extend/plugin/news-manager/43/

The bits that need to be converted to nginx are:

RewriteRule ^news/tag/([^/.]+)/?$ index.php?id=news&tag=$1 [L]
RewriteRule ^news/post/([^/.]+)/?$ index.php?id=news&post=$1 [L]
RewriteRule ^news/page/([^/.]+)/?$ index.php?id=news&page=$1 [L]
RewriteRule ^news/archive/([^/.]+)/?$ index.php?id=news&archive=$1 [L]

Ideally, I would like the rules to be flexible enough to adapt to any path, as in changing
from 'news' to 'blog' without redoing the whole rewrite. But any option will do, really.

Sorry for hijacking this thread, but I didn't want to start a new one since it's the same subject.