Best configuration for wordpress based site

Posted October 23, 2014 10.3k views

Since I switched to digitalocean, I started to read some guides and tutorials to optimize wordpress for best performance when it comes to caching,but I found so many opinions, I don’t know which to follow.
Some say apache, others nginx. Memcache, varnish,nginx reverse proxy with apache, w3 total cache, xcache,APC,self hosted cdn from subdomain,apache’s mod-cache with disk-cache and memcache,etc. There are so many options..
I understand that each one of them serves a specific purpose, but I just want to hear some clear opinions.
Which is in your opinion the best option for a wordpress site with a lot static content, videos(embeded not self hosted), pictures, with over 5000 visitors/day and the 10$ price plan.
Should I go with memcahed option even If I have 1GB memory, or disk cache even If it’s slower?
What was the best config for you?
From what I understand, nginx is the right choice when it comes to static content, but what should I add with it?Varnish,xcache,memcache?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
3 answers

When you’re using a reverse caching proxy it doesn’t really matter what you’re using on your backends. As long as you’re familiar and used to it, it’ll do. I prefer Nginx, simply because the configuration is a lot more clear.

Now - back to all the other names you’ve dropped. Most of them do more or less the same, just with a slightly different approach. I doubt you’ll see much difference between XCache and APC, they are both opcode caching.

Memcached is cool if you have multiple nodes and want a shared cache, but given that you only have one, I don’t really see much gain in using it as a key value store over, say, APC. APC is both a key value store and opcode cache.

Using a different (cookieless) sub-domain for a pseudo-CDN can give you slightly faster load times as you trick the browser into opening more connections in parallel to your server. I wouldn’t spend much time on this before you’ve settled on a proper reverse cache and chosen a opcode cache.

You can never go wrong with Varnish, but it adds a little complexity to your stack. If you have more or less only anonymous traffic (ie. not logged in) Varnish will solve all your issues, as long page renders will hardly ever occur anyway. There is also a plugin to Wordpress that integrates it with Varnish, so you can clear the cache when posting new articles and such.

  • I am currently using nginx reverse caching proxy with apache and w3 total cache and self cdn with generic mirror to 4 subdomain. The site works well but has moments when it hangs for 10-15 seconds. I’ll post the nginx conf and vhost conf to check if everything is correctly set.
    Is there any point in using varnish with this configuration?

  • When you’re using a reverse proxy you don’t really need tools like W3 Total Cache. What they essentially do is generate static pages with are faster to deliver, more or less exactly the same as a reverse cache does, only it stores them in memory and request pages that don’t already exist in cache from the backend server.

    There is little point in using Varnish when you have configured Nginx as a reverse cache. Varnish do however have really good cache invalidation mechanisms.

    I bet the hang you’re seeing is W3 Total Cache generating new pages every now and then. Using that many subdomains might actually slow things down given all the DNS requests that has to be made in order to start downloading assets. At least something to think about.

  • Thanks for the answer. I arrived home, so I can post my configs.
    The apache vh conf(/var/apache2/ file looks like this:

         DocumentRoot /var/www/domain/
      <Directory /var/www/domain>
          Options Indexes FollowSymLinks
          AllowOverride All
          Order allow,deny
          allow from all
         ErrorLog /home/user/logs/error.log
         CustomLog /home/user/logs/access.log combined

    Then I installed nginx and set the nginx.conf like this:

    user username; #change to the same user apache runs as
    worker_processes 1; #change to the number of your CPUs/Cores
    worker_rlimit_nofile 8192;
    error_log /var/log/nginx/error.log;
    pid /var/run/;
    events {
      worker_connections 1024;
      use epoll;
      accept_mutex off;
    http {
      server_names_hash_bucket_size 64;
      include /etc/nginx/mime.types;
      default_type application/octet-stream;
      access_log /var/log/nginx/access.log;
      sendfile on;
      tcp_nopush on;
      keepalive_timeout 65;
      client_max_body_size 100M;
      # reverse proxy options
      proxy_redirect off;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      # gzip compression options
      gzip on;
      gzip_http_version 1.0;
      gzip_comp_level 6;
      gzip_min_length 0;
      gzip_buffers 16 8k;
      gzip_proxied any;
      gzip_types text/plain text/css text/xml text/javascript application/xml application/xml+rss application/javascript application/json;
      gzip_disable "MSIE [1-6]\.";
      gzip_vary on;
      # include virtual hosts configuration
      include /etc/nginx/virtual.d/*.conf;

    After this, I created the file in /etc/nginx/virtual.d that looks like this:

    proxy_cache_path  /var/lib/nginx/cache  levels=1:2   keys_zone=staticfilecache:180m  max_size=500m;
    proxy_temp_path /var/lib/nginx/proxy;
    proxy_connect_timeout 30;
    proxy_read_timeout 120;
    proxy_send_timeout 120;
    #IMPORTANT - this sets the basic cache key that's used in the static file cache.
    proxy_cache_key "$scheme://$host$request_uri";
    upstream wordpressapache {
            #The upstream apache server. You can have many of these and weight them accordingly,
            #allowing nginx to function as a caching load balancer 
            server weight=1 fail_timeout=120s;
    server {
      listen 80;
      access_log off;
      error_log off;
      location / { proxy_pass; }
      location ~* ^.+\.(htm|html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|bz2|pdf|odt|txt|tar|bmp|rtf|js|swf|avi|mp4|mp3|ogg|flv)$ {
        expires 30d; #adjust to your static content's update frequency
        root /var/www/domain;

    Which guide would you suggest me to follow to install Varnish?

Simply put,

nginx with it’s built in caching.

This negates the need for any back end tweaks or extra processes like memcache etc.

If you have lots of logged in content then I would run the latest and greatest php5-fpm which already has zends opcache built in. The opcache will cache all php queries from nginx which should speed things up nicely while keeping cpu processes down.

The above setup should negate the need for you to mess about with mysql although you should make sure that the mysql query cache is enabled :)

Good luck

  • Just installed Varnish and I am satisfied with the performance.I am running the apache with nginx reverse proxy cache and Varnish. I disabled W3 Total Cache and some useless plugins. Noe I try to setup a subdomain for all images to send multiple requests.
    On homepage it takes approx. 0,600 sec to call 160 queries. I guess it’s good, Tell me if I am wrong.

  • You don’t really need both Nginx and Varnish in your stack, since you’ve configured them to do the exact same thing. You can however replace both Varnish and Apache with only Nginx and still have a reverse cache, but I’m not sure if that is within your current scope.

    600ms just in the database isn’t awful, but it’s far from good. But as @zemadeiran has pointed out, you don’t really need to worry that much about it when you’re using a reverse caching proxy. Say you have a 95% cache hit rate only 5 out of every 100 requests will end up on your backend server.

  • I came back with another question. With this stack ngnix/varnish/apache, how should the requests be made?
    Apache listening on port 8080, nginx listening on port 80 with proxy_pass to varnish on localhost:6081, and varnish with backend to port 8080?

  • Again - you don’t need Varnish when you’ve configured (as you have) Nginx as a reverse caching proxy.

    You want all traffic to first hit your reverse cache then your backend servers. So, Nginx (80) -> Apache2 (8080).

As @vegardx already explained a good way to load your WordPress based website faster however only server configuration can not make your WordPress site fast.. Your can use Free WordPress CDN which can decrease your loading speed 3 times. It based on W3 Cache plugin self hosted Content Delivery Network