Rory's Blog
Home
Blog
Projects
Facebook
Google+
Github
RSS

Site Now on Nginx

08/29/14

When I first setup this site for blogging purposes, it was for Rosse's blog, Ramblings of Self Improvement. I decided to setup a wordpress blog for her and as such I followed the instructions here for doing just that.

Those instructions assumed you wanted to use an apache server configuration. I didn't know what I wanted to use, or even that I could have wordpress running with a non-apache setup. Now, I know just a little better, because I plan on eventually having my site and blog running with a tornado backend.

As far as I can tell, it turns out I can't just plug tornado into the apache setup somewhere. There are, however, tutorials for doing exactly that with nginx. I could even plug apache into nginx if I understand it correctly. Though I honestly don't know why I would want to do that (I'm still pretty new to all this server magic).

Anyways, switching over was all pretty straight-forward, actually, except for a "Bad Gateway 502" error that took more googling than I would have liked (more on that below).

The Switch

First, there was the necessary googling. It got me to this tutorial for switching a wordpress blog from apahe to nginx.

I installed nginx (though I might've been told it was already installed):

sudo apt-get install nginx

Then I installed php5-fpm (definitely wasn't installed):

sudo apt-get install php5 php5-cgi php5-fpm

Then I went to /etc/php5/fpm/pool.d/www.conf and switched:

listen = 127.0.0.1:9000

To:

listen = /var/run/php5-fpm.sock

And then I went to /etc/nginx/sites-available/. I copied the default file into a ramblingsofselfimprovement and uncommented the already provided php regex server code. I added a symbolic link to ramblingsofselfimprovement to the sites-enabled directory. I also switched:

server_name localhost

To:

server_name ramblingsofselfimprovement.www.ksionda.me

And:

root /usr/share/nginx/www;

To:

root /usr/share/wordpress;

Then I switched off apache and turned on nginx

sudo service apache2 stop && sudo service nginx start

And... "Bad Gateway 502". What? Why?

I quickly made another copy of the default file into a ksionda file (for my site). Setting all the variables and directories for my site instead of Rosse's wordpress site.

My site came up fine. I reasoned it must be the php5-fpm setup (as wordpress uses php stuff, and my site doesn't). So I googled for a bit and got a lot of different solutions to my problem, until eventually I found one that worked for me.

In /etc/php5/fpm/pool.d/www.conf I switched:

;listen.owner = www-data
;listen.group = www-data
;listen.mode = 0660

To:

listen.owner = www-data
listen.group = www-data
listen.mode = 0660

Restarted php5-fpm, and everything worked fine and dandy.

Nothing looks or works differently, making this a refactoring, but now I can start morphing my site into something that runs on Tornado, which will hopefully lead to some fun learning on my end, and a site with better features and stuff (though that's a secondary goal).