Last active
September 29, 2022 19:48
-
-
Save dietrichmax/845737a8de8b186aa27a699760eba691 to your computer and use it in GitHub Desktop.
Nginx Configuration for Nextjs
This file contains 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
server { | |
# Listen HTTP | |
listen 443 ssl; | |
listen [::]:443 ssl; | |
server_name domain.com; | |
gzip on; | |
gzip_proxied any; | |
gzip_comp_level 4; | |
gzip_types text/css application/javascript image/svg+xml; | |
# Proxy Config | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection 'upgrade'; | |
proxy_set_header Host $host; | |
proxy_cache_bypass $http_upgrade; | |
location /_next/static { | |
proxy_cache STATIC; | |
proxy_pass http://localhost:3000; | |
} | |
location /static { | |
proxy_cache STATIC; | |
proxy_ignore_headers Cache-Control; | |
proxy_cache_valid 60m; | |
proxy_pass http://localhost:3000; | |
} | |
location / { | |
proxy_pass ttp://localhost:3000; | |
} | |
} | |
### redirect www to non-www | |
server { | |
listen 443 ssl http2; | |
server_name www.domain.com; | |
return 301 https://domain.com$request_uri; | |
} | |
### redirect to https | |
server { | |
# Listen HTTP | |
listen 80; | |
listen [::]:80; | |
server_name domain.com www.domain.com; | |
# Redirect HTTP to HTTPS | |
return 301 https://$host$request_uri; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment