Skip to content

Instantly share code, notes, and snippets.

@magician11
Last active March 1, 2018 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magician11/aa5f34fb12f267fe11672e6e32fba506 to your computer and use it in GitHub Desktop.
Save magician11/aa5f34fb12f267fe11672e6e32fba506 to your computer and use it in GitHub Desktop.
Server block example for a WordPress site on Nginx on a DigitalOcean droplet
server {
server_name www.goforself.me goforself.me;
listen 80;
client_max_body_size 20M;
port_in_redirect off;
access_log /var/log/nginx/goforself.me.access.log;
error_log /var/log/nginx/goforself.me.error.log error;
root /var/www/goforself;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
# Cache static files for as long as possible
location ~*.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf|cur)$ {
expires max;
log_not_found off;
access_log off;
}
# Deny public access to wp-config.php
location ~* wp-config.php {
deny all;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment