Created
October 13, 2021 21:24
-
-
Save laurenashpole/352cbd10fbf35483b79a24a1c1c4e52d to your computer and use it in GitHub Desktop.
Basic Nginx Configuration with Caching
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
server_name www.laurenashpole.com; | |
root /root/laurenashpole/.next/pages; | |
index index.html index.htm index.nginx-debian.html; | |
# SSL | |
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; | |
proxy_pass https://127.0.0.1:8443; | |
} | |
} | |
server { | |
listen 80; | |
listen [::]:80; | |
server_name laurenashpole.com; | |
return 301 https://www.laurenashpole.com$request_uri; | |
} | |
server { | |
listen 80; | |
listen [::]:80; | |
server_name www.laurenashpole.com; | |
return 301 https://www.laurenashpole.com$request_uri; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment