Skip to content

Instantly share code, notes, and snippets.

@dbtlr
Created January 6, 2017 18:45
Show Gist options
  • Save dbtlr/478f6b2218e90e825395a24b788083be to your computer and use it in GitHub Desktop.
Save dbtlr/478f6b2218e90e825395a24b788083be to your computer and use it in GitHub Desktop.
Jekyll Nginx config, assumes you're using a versioned deployment dir that matches the domain name and uses Let's Encrypt SSL cert.
server {
listen 80;
server_name yourdomain.com;
return 301 https://yourdomain.com$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name yourdomain.com;
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
access_log /var/www/yourdomain.com/logs/access.log;
error_log /var/www/yourdomain.com/logs/error.log;
error_page 404 /404.html;
## Root and index files.
root /var/www/yourdomain.com/current/;
index index.html;
default_type "text/html";
autoindex off;
location /404.html {
internal;
}
## If no favicon exists return a 204 (no content error).
location = /favicon.ico {
try_files $uri =204;
log_not_found off;
access_log off;
}
## Don't log robots.txt requests.
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
if (!-f "${request_filename}index.html") {
rewrite ^/(.*)/$ /$1 permanent;
}
if ($request_uri ~* "/index.html") {
rewrite (?i)^(.*)index\.html$ $1 permanent;
}
if ($request_uri ~* ".html") {
rewrite (?i)^(.*)/(.*)\.html $1/$2 permanent;
}
location / {
try_files $uri.html $uri $uri/ =404;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment