How to setup Nginx for WordPress on DigitalOcean


I decided to switch from Apache to Nginx.

I have a couple of WordPress sites on a DigitalOcean droplet, so I needed to reconfigure them to be used with Nginx. I basically followed this guide which was great for most of it, but I was still not getting the sites loading properly (404 errors, forbidden).

I needed to tweak the server block files to get it working, and this is what I came up with..

In /etc/nginx/sites-available create a separate file for each domain you’re hosting. For one of mine, I called it goforself.me to correspond with my Go For Self website, and this is the contents of that file…

https://gist.github.com/magician11/aa5f34fb12f267fe11672e6e32fba506

Then in /etc/nginx/sites-enabled/ create a symlink like so

ln -s ../sites-available/goforself.me .

I like to have my sites being only accessed over HTTPS, so there are a couple more steps to get this going. I basically followed this guide, and this is the essence of what needs to be done..

First install certbot

https://gist.github.com/magician11/4be656ba1c8c88708361a73a94c3497d

For my Go For Self website setup above, I then type

sudo certbot --nginx -d goforself.me -d www.goforself.me

and I choose option 2 to always redirect to HTTPS.

And that is pretty much it. You’ll need to restart nginx to get it going.. so I go

service nginx restart

Any questions, let me know!


4 responses to “How to setup Nginx for WordPress on DigitalOcean”

  1. Just a quick note to say thank you for posting this it helped me fix a problem with a ghost install on digital ocean which would only load https:// and not the http://www

Leave a Reply

Your email address will not be published.