Created
December 16, 2024 18:01
-
-
Save zacharytyhacz/3163e1cdaff4dfcbe520f5f2c0ff9242 to your computer and use it in GitHub Desktop.
Nextjs 15 NGINX config
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
# must run `npm run build` before building | |
# Once you go 'production' deployed, make sure to NEXTAUTH_URL and AUTH_TRUST_HOST | |
server { | |
server_name sub.example.com; | |
# no index file required | |
root /var/www/NEXTJS_ROOT; | |
# Serve static assets. Adjust cache as needed | |
location /_next/static/ { | |
alias /var/www/NEXTJS_ROOT/.next/static/; | |
expires 1y; | |
access_log off; | |
add_header Cache-Control "public, max-age=31536000, immutable"; | |
} | |
# Serve favicon. Idk in deployment the src/app/favicon.ico fails to server | |
location /favicon.ico { | |
alias /var/www/NEXTJS_ROOT/public/favicon.ico; | |
} | |
# Serve public assets | |
location / { | |
# If the file exists in public/ directory, serve it | |
try_files $uri @nextjs; | |
} | |
# Proxy GET and POST requests to Next.js | |
location @nextjs { | |
proxy_pass http://localhost:7777; | |
proxy_http_version 1.1; | |
# Required headers for Next.js server. If you use Authjs, make sure to see AUTH_TRUST_HOST env var | |
proxy_set_header Host $host; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Forwarded-Proto $scheme; | |
} | |
# Error handling | |
error_page 404 /404.html; | |
location = /404.html { | |
root /var/www/NEXTJS_ROOT/public; | |
internal; | |
} | |
listen [::]:80; | |
listen 80; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment