2025-06-02 21:50:39 +00:00
|
|
|
|
{{ $proxy_settings := "proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $http_connection; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Port $server_port; proxy_set_header X-Request-Start $msec;" }}
|
2024-04-07 16:39:37 +00:00
|
|
|
|
|
2023-10-09 20:47:18 +00:00
|
|
|
|
{{ range $port_map := .PROXY_PORT_MAP | split " " }}
|
2024-03-13 12:35:49 +00:00
|
|
|
|
{{ $port_map_list := $port_map | split ":" }}
|
|
|
|
|
{{ $scheme := index $port_map_list 0 }}
|
|
|
|
|
{{ $listen_port := index $port_map_list 1 }}
|
|
|
|
|
{{ $upstream_port := index $port_map_list 2 }}
|
2023-10-09 20:47:18 +00:00
|
|
|
|
|
|
|
|
|
server {
|
|
|
|
|
{{ if eq $scheme "http" }}
|
2023-10-10 10:48:33 +00:00
|
|
|
|
listen [::]:{{ $listen_port }};
|
2023-10-09 20:47:18 +00:00
|
|
|
|
listen {{ $listen_port }};
|
|
|
|
|
server_name {{ $.NOSSL_SERVER_NAME }};
|
2025-06-02 21:50:39 +00:00
|
|
|
|
|
|
|
|
|
# Redirect HTTP to HTTPS
|
|
|
|
|
return 301 https://$server_name$request_uri;
|
2024-12-20 17:35:59 +00:00
|
|
|
|
|
2023-10-09 20:47:18 +00:00
|
|
|
|
{{ else if eq $scheme "https" }}
|
2023-10-10 10:48:33 +00:00
|
|
|
|
listen [::]:{{ $listen_port }} ssl http2;
|
2023-10-09 20:47:18 +00:00
|
|
|
|
listen {{ $listen_port }} ssl http2;
|
|
|
|
|
server_name {{ $.NOSSL_SERVER_NAME }};
|
2025-06-02 21:50:39 +00:00
|
|
|
|
|
2025-06-02 22:45:06 +00:00
|
|
|
|
# SSL конфигурация (dokku дефолты)
|
2023-10-09 20:47:18 +00:00
|
|
|
|
ssl_certificate {{ $.APP_SSL_PATH }}/server.crt;
|
|
|
|
|
ssl_certificate_key {{ $.APP_SSL_PATH }}/server.key;
|
2025-06-02 21:50:39 +00:00
|
|
|
|
|
|
|
|
|
# Базовые заголовки безопасности
|
|
|
|
|
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
|
|
|
|
add_header X-Frame-Options "SAMEORIGIN" always;
|
|
|
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
|
|
|
|
|
|
|
|
# Скрыть версию nginx
|
|
|
|
|
server_tokens off;
|
2023-10-09 20:47:18 +00:00
|
|
|
|
{{ end }}
|
|
|
|
|
|
2025-06-02 21:50:39 +00:00
|
|
|
|
# Логирование (dokku дефолты)
|
|
|
|
|
access_log /var/log/nginx/{{ $.APP }}-access.log;
|
|
|
|
|
error_log /var/log/nginx/{{ $.APP }}-error.log;
|
|
|
|
|
|
|
|
|
|
# Размер загружаемых файлов
|
|
|
|
|
client_max_body_size 100M;
|
|
|
|
|
|
|
|
|
|
# Улучшенное сжатие
|
|
|
|
|
gzip on;
|
|
|
|
|
gzip_vary on;
|
|
|
|
|
gzip_min_length 1000;
|
|
|
|
|
gzip_comp_level 6;
|
|
|
|
|
gzip_types text/plain text/css text/xml text/javascript application/javascript application/json image/svg+xml;
|
2024-12-20 17:35:59 +00:00
|
|
|
|
|
2024-12-17 17:14:01 +00:00
|
|
|
|
location / {
|
2025-01-28 22:23:02 +00:00
|
|
|
|
proxy_pass http://{{ $.APP }}-{{ $upstream_port }};
|
2024-12-17 17:14:01 +00:00
|
|
|
|
{{ $proxy_settings }}
|
2023-10-09 20:47:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2025-06-02 21:50:39 +00:00
|
|
|
|
# Статические файлы с долгим кэшированием
|
|
|
|
|
location ~* \.(css|js|ico|png|jpg|jpeg|gif|svg|webp|woff|woff2|ttf|eot)$ {
|
|
|
|
|
proxy_pass http://{{ $.APP }}-{{ $upstream_port }};
|
|
|
|
|
{{ $proxy_settings }}
|
2023-10-10 10:52:43 +00:00
|
|
|
|
|
2025-06-02 21:50:39 +00:00
|
|
|
|
expires 1y;
|
|
|
|
|
add_header Cache-Control "public, immutable";
|
|
|
|
|
add_header Vary "Accept-Encoding";
|
|
|
|
|
access_log off;
|
2024-02-27 09:05:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2025-06-02 21:50:39 +00:00
|
|
|
|
# Включение дополнительных конфигураций dokku
|
|
|
|
|
include {{ $.DOKKU_ROOT }}/{{ $.APP }}/nginx.conf.d/*.conf;
|
2023-10-09 20:47:18 +00:00
|
|
|
|
}
|
|
|
|
|
{{ end }}
|
|
|
|
|
|
|
|
|
|
{{ range $upstream_port := $.PROXY_UPSTREAM_PORTS | split " " }}
|
|
|
|
|
upstream {{ $.APP }}-{{ $upstream_port }} {
|
2023-10-10 10:48:33 +00:00
|
|
|
|
{{ range $listeners := $.DOKKU_APP_WEB_LISTENERS | split " " }}
|
|
|
|
|
{{ $listener_list := $listeners | split ":" }}
|
|
|
|
|
{{ $listener_ip := index $listener_list 0 }}
|
|
|
|
|
{{ $listener_port := index $listener_list 1 }}
|
2025-06-02 21:50:39 +00:00
|
|
|
|
server {{ $listener_ip }}:{{ $upstream_port }};
|
2023-10-09 20:47:18 +00:00
|
|
|
|
{{ end }}
|
2023-10-10 10:48:33 +00:00
|
|
|
|
}
|
2024-01-11 16:52:10 +00:00
|
|
|
|
{{ end }}
|