Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Basic Nginx Configuration with Caching
map $sent_http_content_type $expires {
default off;
text/html epoch;
text/css max;
application/javascript max;
~image/ max;
font/ttf max;
font/opentype max;
application/font-woff max;
font/woff2 max;
server {
listen 443 ssl;
listen [::]:443 ssl;
root /root/laurenashpole/.next/pages;
index index.html index.htm index.nginx-debian.html;
ssl_certificate /path/to/ssl-cert.crt;
ssl_certificate_key /path/to/ssl-cert-key.key;
# Expires
expires $expires;
# Gzip
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
# Reverse proxy
location / {
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
server {
listen 80;
listen [::]:80;
return 301$request_uri;
server {
listen 80;
listen [::]:80;
return 301$request_uri;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment