4 ms·
My Wordpress blog used to go down because of HN. I fixed that as follows. 1. Use the Wordpress supercache plugin. 2. Put Apache behind Nginx, and limit the nu
by FooBarWidget 12y ago
My Wordpress blog used to go down because of HN. I fixed that as follows.
1. Use the Wordpress supercache plugin.
2. Put Apache behind Nginx, and limit the number of Apache processes to ~6. This way you're effectively using Apache as a "PHP app server", simulating an architecture similar to Passenger/Unicorn. Nginx acts only as a buffering reverse proxy, shielding Apache from slow clients.
Why this instead of running Wordpress/PHP through Nginx using php-fpm? It's because Apache is just easier: mod_rewrite rules work automatically, etc.
- JeremyMorgan 12y agoNever configured Apache that way, that sounds really interesting. I was running the site on a fairly well tuned LEMP stack and was using a cache plugin (forgot the name) but it would still choke fairly often. Since the content of my site only changes a couple times a month I started migrating away from towards a static solution. I'm not trying to say WP is bad but I think if your content is relatively static and you aren't doing a ton of updating, just make it static HTML instead of doing hacky cache stuff. It's simple, secure and runs on any type of server. The only thing that's lacking right now is a really solid static site generator. Octopress/Jekyll are good solutions but can be a bit frustrating and not very portable.
- jmccree 12y agoUsing nginx/varnish as a caching reverse proxy in front of apache/php is rather common. You get all the ease of use of Apache (mod_rewrite instant .htaccess rule changes, mod_php, etc.) , ability to use whatever cpu intensive plugins/code you want in your application, and once the page is cached it loads instantly for as long as you cache it. Nginx can be configured to serve static assets directly or your app can use CDN links. I've never really understood the recent fascination with static site generators. I get that it's neat you can upload just everything to S3 and host it there with no servers, but then if you want to change something site wide you have to reload everything. Dynamic app + with caching reverse proxy + optional CDN is a tried and true method. I've been on projects that use this method with small VMs to power sites with tons of traffic.
- cbhl 12y agoI've had strong recommendations for nanoc and middleman. Additional static site generators can be found all over; one good resource is this list: http://blog.iwantmyname.com/2014/05/the-updated-big-list-of-static-website-generators-for-your-site-blog-or-wiki.html http://blog.iwantmyname.com/2014/05/the-updated-big-list-of-...
- nilved 12y agoThis is first time I've seen the words "Apache is just easier" in that arrangement. I think php-fpm is significantly easier to set up than Apache and expect it to be more performant with less resources.
- okaram 12y agoThis probably depends more on experience, and which OS/platform you're using; although I don't do it a lot, I've configured Apache servers several dozen times, whereas I've only done nginx a couple of times, so it is 'easier' for me. Also, on ubuntu (and centos, but haven't used it in a while), it is something like 'apt-get install apache-mod-php' and everything is there :)
- InclinedPlane 12y agoYup. I've been running nginx + php-fpm for pretty much as long as it's been possible, and it's pretty great with far less hassle than most other configs.
- mjevans 12y agoIt's easier for things that are written in broken ways that work best with Apache because that's the only platform they targeted.
- smacktoward 12y agoI'm not even sure step 2 is necessary, my WP blog has hit HN a few times and the supercache plugin alone has been more than sufficient to handle it. Really the big problem at this point is that stock WordPress falling over under even moderate traffic is such a common experience that having caching broken out into an optional plugin doesn't make a whole lot of sense. WP should probably ship with at least a basic caching solution built in.
- Encosia 12y agoCaching HTML to disk via W3 Total Cache or WP Super Cache is really all you need on most hosting. I never got around to putting Apache behind nginx, but have still survived some relatively large traffic spikes for a personal blog (e.g. 100k+ page views in a few hours) without any trouble at all. Not to say that your setup isn't better (it obviously is), but I want to make sure no one's intimidated by the task of hardening their WP install because they think they'll need to do both 1 and 2 for it to be worthwhile.
- driverdan 12y agoNginx + PHP-FPM isn't necessarily hard to setup, just different. It will be much faster than nginx in front of apache.
- ibudiallo 12y agoIn my case, I did two things: 1. Add memcached 2. Serve static files via nginx It allowed me to handle 2.9 million requests I documented it here: http://idiallo.com/blog/handling-1-million-web-request http://idiallo.com/blog/handling-1-million-web-request
- JeremyMorgan 12y agoNice! I tweeted this, you might see some additional traffic, definitely something my group of friends would be interested in.
- ibudiallo 12y agoThanks, and I'm glad you found it interesting.
- stephen_g 12y agoYou can do the rewrite with a single nginx command: try_files $uri $uri/ /index.php?$args;