Last active
May 13, 2025 12:11
-
-
Save MakStashkevich/738d88985784aa4f079e22a8596e9294 to your computer and use it in GitHub Desktop.
Standalone Next.js 15+ configuration file for nginx proxy. / Standalone Next.js 15+ версии конфигурация для прокси-сервера nginx
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 $http_upgrade $connection_upgrade { | |
default upgrade; | |
'' close; | |
} | |
# Сервер для HTTP (редирект на HTTPS) | |
server { | |
listen 80; | |
listen [::]:80; # Поддержка IPv6 | |
server_name www.site.com site.com; | |
server_tokens off; | |
# Настройка для certbot (для обновления SSL сертификатов) | |
location /.well-known/acme-challenge/ { | |
root /var/www/certbot; | |
allow all; | |
} | |
# Редирект с HTTP на HTTPS | |
location / { | |
return 301 https://$host$request_uri; | |
} | |
} | |
# Сервер для HTTPS | |
server { | |
listen 443 ssl http2; | |
listen [::]:443 ssl http2; # Поддержка IPv6 | |
server_name site.com www.site.com; | |
server_tokens off; | |
# Указываем пути до сгенерированной папки standalone Next.js | |
set $root /home/site.com/site/.next/standalone; | |
set $build $root/.next; | |
# SSL-сертификаты | |
ssl_certificate /etc/letsencrypt/live/site.com/fullchain.pem; | |
ssl_certificate_key /etc/letsencrypt/live/site.com/privkey.pem; | |
include /etc/letsencrypt/options-ssl-nginx.conf; | |
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; | |
# Логирование | |
access_log /var/log/nginx/site_access.log combined; | |
# Настройки для улучшения производительности | |
http2_max_field_size 16k; | |
http2_max_header_size 32k; | |
# Проксирование запросов на Next.js (порт 2401) | |
location @proxy { | |
proxy_pass http://localhost:2401; # Адрес Next.js сервиса | |
proxy_set_header Host $http_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_redirect http://localhost:2401 $scheme://$http_host; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection $connection_upgrade; | |
proxy_read_timeout 20d; | |
proxy_buffering off; | |
} | |
# Пробуем найти публичный файл, если не находим грузим прокси приложение | |
location / { | |
root $root/public; | |
try_files $uri @proxy; | |
} | |
# Загрузка статичных файлов Next.js | |
location /_next/static { | |
alias $build/static; | |
# Кешируем файлы в браузере на 1 день | |
expires 1d; | |
try_files $uri $uri/ =404; | |
} | |
# Безопасность | |
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; | |
add_header X-Content-Type-Options nosniff; | |
add_header X-Frame-Options SAMEORIGIN; | |
add_header X-XSS-Protection "1; mode=block"; | |
# Ограничение на размер загружаемых файлов | |
client_max_body_size 10M; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment