Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


A modern wordpress config
New on LowEndTalk? Please Register and read our Community Rules.

A modern wordpress config

marrcomarrco Member
edited June 2012 in General

i've seen a few benchmarks that memcached, w3c or nginx fastcgi_cache all provide about the same performance advantages, so i tried to hack and modify a few samples in order to find a great caching WP config that works without using too much resources.

In order to run this you must have a modern NGINX version ie. on squeeze apt-get -t squeeze-backports install nginx

suggestions?

## define here or in /etc/nginx/nginx.conf
fastcgi_cache_path  /var/cache/nginx/social  levels=1:2 keys_zone=WPCACHE:10m inactive=15m;
##
                
map $http_cookie $logged_in {
    default 0;
    ~wordpress_logged_in 1; # This will return true if user is logged in
}

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

server {
        listen 80;
        server_name www.mywebsite.net;
        charset utf-8;
        access_log off;
        root /var/www/mywebsite.net;
        index index.php;
        
        location / {
            try_files       $uri $uri/ /index.php?q=$uri&$args;
            fastcgi_cache_bypass $logged_in;
            fastcgi_no_cache $logged_in;
        }

        location ~* \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_index index.php;
        try_files $uri =404;
        fastcgi_cache_bypass $logged_in;
        fastcgi_no_cache $logged_in;
        fastcgi_pass unix:/var/run/www/php.sock;
        fastcgi_cache WPCACHE;
          fastcgi_cache_key "$scheme$request_method$host$request_uri";
          fastcgi_cache_valid  200 302  10m;
          fastcgi_cache_valid  404      1m;
          fastcgi_cache_use_stale updating;
          expires 20m;
        }

       location ^~ /wp-admin/*\.php {
                try_files $uri /admin/index.php?q=$uri&$args;
                include /etc/nginx/fastcgi_params;
                fastcgi_cache_bypass $logged_in;
                fastcgi_no_cache $logged_in;
                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) -
        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;}
        }
}
Thanked by 1djvdorp

Comments

  • Isn't Nginx with php-fpm and APC fast enough yet :P ?

  • @djvdorp said: Isn't Nginx with php-fpm and APC fast enough yet :P ?

    Nothing wrong with further optimization, as long as you have the time, why not...

    one guy goes to the repair shop with his car.
    -What's wrong ? Asks the mechanic.
    -See, one year ago you put me some fuel saver which optimizes air intake and saves up to 30% gas...
    - I see, it is broken ?
    - No-no, please hear me out... So after a while I was happy with it as it did the job, then I modified my gearbox to save 10% more, then I optimized the injection for further up to 50%, I learned to drive smoothly and use breaks less for 20% more save, took special tyres, reduced car weight, used no more AC, I dont even remember all the things I did to fight the pump prices increase, but there is a problem...
    - Aha, what is it ?
    - You see, yesterday I began to have engine problems, it got flooded often and then I remembered I didnt put fuel in a long time and the gauge is still on full, then opened the tank and it was overflowing...

    M

    Thanked by 1djvdorp
  • @Maounique said: Nothing wrong with further optimization, as long as you have the time, why not...

    You are right about that, but I was just wondering if it was 'hobbyism' or a real problem with the performance of my mentioned config :)

  • marrcomarrco Member

    i'm just trying to learn and exploring the nginx new (v. 0.86+) fastcgi_cache/no_cache/bypass in order to get a fast and compact config. Of course i can use a varnish cache or a reverse proxy (or one of the many other options available), but why not exploring new nginx features? Maybe i can squeeze a few more speed using less resources and with a easier config.

    I still miss the time when LET was a tech board where i learned lots of new tricks.

    Thanked by 2djvdorp Maounique
  • @marrco said: I still miss the time when LET was a tech board where i learned lots of new tricks.

    I agree with you on this, sorry if my comment did not come out correctly as English is not my native language. I was just wondering if it was your curiousity/geekyness or a performance problem you hit. I'd love to hear your experiences as I would like to try stuff like this myself when I get time, and I always love to learn new things from this community!

  • @marrco said: I still miss the time when LET was a tech board where i learned lots of new tricks.

    it still is, but maybe you learned most tricks already :P
    Besides, for heavy traffic sites, every bit counts. We wouldnt do that on production servers.
    Personally I am not an nginx guru, I keep telling myself one day I will get to study that but I also fear it may become commercial soon...
    M

Sign In or Register to comment.