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 to correspond with my Go For Self website, and this is the contents of that file…

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

ln -s ../sites-available/ .

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

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

sudo certbot --nginx -d -d

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.