Top Banner
Marko Heijnen CODEKITCHEN My complicated site WordCamp Croatia, Rijeka 2015
38

My complicated WordPress site

Apr 12, 2017

Download

Engineering

Marko Heijnen
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: My complicated WordPress site

Marko Heijnen CODEKITCHEN

My complicated siteWordCamp Croatia, Rijeka 2015

Page 2: My complicated WordPress site

Who can remember how their site was hosted 10 years ago?

Page 3: My complicated WordPress site

Web isn’t the same as it was in the nineties

Page 4: My complicated WordPress site

Internet Users 1990

© Copyright Sasi Group (University of Sheffield) and Mark Newman (University of Michigan).

Page 5: My complicated WordPress site

Internet Users 2002

© Copyright Sasi Group (University of Sheffield) and Mark Newman (University of Michigan).

Page 6: My complicated WordPress site

Now around 43% of the world is connected

And almost 50% users living in Asia

Page 7: My complicated WordPress site

So shared hosting isn’t enough anymore

Page 8: My complicated WordPress site

My site’s history

Page 9: My complicated WordPress site

My site’s history• Started in 2008

• Hosted on a crappy shared host

• Switched to another shared host

• Switched to a VPS in 2010 with Directadmin

• Start using nginx in 2012 on another VPS

• In 2015 switched to Digital Ocean with multiple servers

Page 10: My complicated WordPress site

Mistakes during the years• Updating Ubuntu breaking the server due to

incompatible kernel

• Wrong configuration of Apache that slowed down the site

• Updating PHP version on Directadmin caused hours of downtime

• Running Debian testing causing dependency issues

Page 11: My complicated WordPress site

Builded up my own cluster

Page 12: My complicated WordPress site

Multiserver setupPublic Private

Loadbalancer

Webserver 1

Webserver 2

Memcached

Elasticsearch

MariaDB

Page 13: My complicated WordPress site

Every server• apt-dater-host

• apticron (only 1 per matching type)

• fluentd (future for logging)

• ufw (firewall)

Page 14: My complicated WordPress site

UFW (firewall)• ufw default deny incoming

• ufw default deny outgoing

• ufw allow out http(s)

• ufw allow out DNS

• ufw allow from {your.home.ip}

• other specific rules

Page 15: My complicated WordPress site

Loadbalancer• nginx mainline (from nginx.org)

• apt-cacher-ng

• modsecurity

Page 16: My complicated WordPress site

Web server• nginx mainline (from nginx.org)

• PHP7 with no fallback

• OPcache

• WP CLI

• Syncing uploads directory (NFS)

• CDN for assets through MaxCDN

Page 17: My complicated WordPress site

OPcache• Turned of check for updated scripts

• Increased max_accelerated_files to 8000

• Increased memory_consumption to 192M

• Enabled fast_shutdown

• enable_file_override = 1

Page 18: My complicated WordPress site

Service server• MariaDB as database

• Memcached as object cache

• Moving to Redis when PHP7 is out

• Elasticsearch to make search better/faster

Page 19: My complicated WordPress site

Multiserver setup

fail2ban modsecurity

ufw apticron

apt-dater-hostufw

apticron (web1) apt-dater-host

ufw apticron

apt-dater-host

Loadbalancer

Webserver 1

Webserver 2

Memcached

Elasticsearch

MariaDB

Public Private

Page 20: My complicated WordPress site

Additional microservice server

Page 21: My complicated WordPress site

What are microservices• Microservices are small, autonomous services that

work together

• Small, and Focused on Doing One Thing Well

Page 22: My complicated WordPress site

Benefits• Offload functionality from WordPress

• Different services can use different programming languages

• High level separation

• If WordPress breaks, the services still keep running

• Ease of Deployment

Page 23: My complicated WordPress site

Benefits• Scale services that require more resources

• In general they have an (REST) API

• Reusable

• Other microservices could call the service to run a task

Page 24: My complicated WordPress site

What I currently have• Handles all cronjobs for the network site

• Node.js services running for WP Central

• Like getting checksums for plugins/themes

Page 25: My complicated WordPress site

Additional server for image manipulation

Page 26: My complicated WordPress site

Thumbor• A python server that can manipulate images

• Done by passing the image url to Thumbor

• A lot like Photon from Jetpack

• Build in image optimizers

• Several kinds of image storages

• Second CDN zone for .webp support

Page 27: My complicated WordPress site

Thumbor installation• apt-get install python python-dev python-pip

libjpeg-dev libpng-dev libtiff-dev libjasper-dev libgtk2.0-dev python-numpy python-pycurl webp python-opencv libwebp-dev libjpeg-progs

• pip install pillow

• pip install thumbor

• thumbor-config > /etc/thumbor.conf

Page 28: My complicated WordPress site

LoadbalancerMemcached

Elasticsearch

MariaDB

My setup

Micro services

Webserver 1

Webserver 2

Thumbor

Public Private

Page 29: My complicated WordPress site

Security

Page 30: My complicated WordPress site

First level server security• Using firewall which blocks all

• Adding rules for opening ports

• SSH is key only

• No PHP execution in wp-content/uploads

Page 31: My complicated WordPress site

First level app security• Super admins are forced to use IPs

• Soon admins are forced to use two factor authentication

Page 32: My complicated WordPress site

Second level security• All log files are stored in a database

• Failed login attempts getting logged

Page 33: My complicated WordPress site

Detection layer• Detection layer when files are added/changed

• What is in your uploads folder (PHP files)

• Detect required updates

• Detect security issues in core/plugins/themes

• List plugins/themes that aren’t used

Page 34: My complicated WordPress site

See also my presentation:Protecting your site by detection

Page 35: My complicated WordPress site

Play, break and learn

Page 36: My complicated WordPress site

Marko Heijnen• Founder of CodeKitchen

• Lead developer of GlotPress

• Core contributor for WordPress

• Organizer for WordCamp Belgrade

Page 37: My complicated WordPress site

Marko [email protected]

@markoheijnen

Page 38: My complicated WordPress site

Thank you for listening

Questions?@markoheijnen

markoheijnen.com

codekitchen.eu