All posts filed under “servers

Nginx proxy_pass a folder to WordPress

After a rash of security updates for WordPress, I finally buckled down to move our install of WordPress off to it’s own server. This would be easy if we were running the blog on it’s own domain, but it was actually living under /blog on our main domain for SEO reasons. Running nginx as a reverse proxy to WordPress on a different machine was not an easy task. A lot of guides did not seem to have the information I needed so here are the steps I took to get it working.

Add the proxy_pass definition to your nginx config:

Update your WordPress settings. This is the key to getting your site to work correctly. Leave the WordPress Address as where the site is hosted, but change the Site Address to be where URLs are to be written as linking to

Screenshot 2015-07-27 21.43.38

I also had to add a rewrite to my .htaccess file to remove trailing slashes:


Be warned that the permalinks section will suggest a .htaccess file which has /blog/ as the RewriteBase, but this just sends things into a redirect loop. Leave it as the standard root setting.

Make sure you also check that the canonical tags generated by your theme are correct. You want to be sure that any references on the WordPress Address URL canonicalise to Site Address URLs.

rvm can not be run with `set -o posix`

Setting up a new Ubuntu 12.04 LTS server I kept getting the error below when trying to run the rvm command.

This was solved by changing the login shell for my user. It prompts for your password and shell which I changed from /bin/sh to /bin/bash.

Logging nginx cookies with dashes

Strangely nginx does not support variable names with dashes or other characters other than lower/uppercase letters, digits or underscores. This means that if you are trying to log cookie values which contain dashes, as in my case, you can’t do it.

Two workarounds are logging the all the cookies in one go, which can be overwhelming:

The other option is to map your cookie names to a variable that can be used by nginx:

Serve a static file on a specific URL in nginx

I recently had to serve a static file on a specific url in nginx. The requirement was that /sapm/jcb should show a specific page, but I of course forgot about the html extension so the end result was my file only appeared on /sapm/jcb.html.

An nginx conf change sorted it all out.