server { listen 80; server_name ntspi.ru www.ntspi.ru; return 301 https://www.ntspi.ru$request_uri; } server { listen 443 ssl http2; server_name ntspi.ru; ssl_certificate /etc/letsencrypt/live/www.ntspi.ru/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/www.ntspi.ru/privkey.pem; return 301 https://www.ntspi.ru$request_uri; } server { listen 443 ssl http2; server_name www.ntspi.ru; # SSL-конфигурация ssl_certificate /etc/letsencrypt/live/www.ntspi.ru/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/www.ntspi.ru/privkey.pem; ssl_trusted_certificate /etc/letsencrypt/live/www.ntspi.ru/chain.pem; ssl_protocols TLSv1.2 TLSv1.3; ssl_prefer_server_ciphers on; ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384'; ssl_session_timeout 1d; ssl_session_cache shared:SSL:50m; ssl_stapling on; ssl_stapling_verify on; resolver 8.8.8.8 8.8.4.4 valid=300s; resolver_timeout 5s; # Ваши текущие настройки gzip on; gzip_disable "msie6"; gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml; gzip_min_length 1024; gzip_comp_level 6; gzip_buffers 16 8k; gzip_proxied any; gzip_vary on; client_max_body_size 200M; large_client_header_buffers 4 128k; root /var/www/public; # Security headers add_header X-Frame-Options "SAMEORIGIN" always; add_header X-Content-Type-Options "nosniff" always; add_header X-XSS-Protection "1; mode=block" always; add_header Referrer-Policy "strict-origin-when-cross-origin" always; add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always; add_header Content-Security-Policy "default-src 'self' https:; script-src 'self' 'unsafe-inline' 'unsafe-eval' https:; style-src 'self' 'unsafe-inline' https:; img-src 'self' data: https: blob:; font-src 'self' data: https:; connect-src 'self' https:; worker-src 'self' blob:; frame-ancestors 'self';" always; location ^~ /jenkins/ { proxy_pass http://jenkins:8080; 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_read_timeout 90; proxy_max_temp_file_size 0; proxy_redirect http:// https://; } location / { add_header Access-Control-Allow-Origin "https://www.ntspi.ru" always; try_files $uri /index.php?$args; } # ======================================================================== # VIKON MODULE SECURITY — Block executable files in module directories # MUST be placed BEFORE location ~ \.php$ to take effect # ======================================================================== location ~ ^/(sveden|abitur)/.*\.(php|php3|php4|php5|php7|php8|phps|phtml|pl|py|pyc|cgi|sh|bash|bat|cmd|exe|com|ps1|psm1|rb|asp|aspx|jsp|cfm)$ { deny all; return 403; access_log /var/log/nginx/blocked_module_scripts.log; } location /sveden/ { alias /var/www/public/sveden/; index index.html; try_files $uri $uri/ /sveden/index.html; expires epoch; add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0"; } location = /sveden { return 301 /sveden/; } location /abitur/ { alias /var/www/public/abitur/; index index.html; try_files $uri $uri/ /abitur/index.html; expires epoch; add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0"; } location = /abitur { return 301 /abitur/; } location /vsoko/ { alias /var/www/public/vsoko/; index index.html; try_files $uri $uri/ /vsoko/index.html; expires epoch; add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0"; } location = /vsoko { return 301 /vsoko/; } # ============================================ # SECURITY: Запрет доступа к чувствительным файлам # ============================================ # Запрет доступа к .env, .git и всем скрытым файлам location ~ /\. { deny all; return 404; } # Запрет доступа к composer, package, lock, readme файлам location ~* (composer\.(json|lock)|package\.(json|lock)|\.md|\.txt|\.log)$ { deny all; return 404; } # Разрешаем доступ к публичным vendor ассетам (log-viewer, и т.д.) # Это статические файлы в public/vendor/ location /vendor/ { # Запрещаем выполнение PHP файлов location ~ \.php$ { deny all; return 404; } # Отдаём статические файлы try_files $uri =404; autoindex off; } # Разрешаем доступ к публичным файлам storage (через symlink public/storage) # Это должны быть ТОЛЬКО изображения, документы и т.д. — НЕ PHP файлы location /storage/ { # Запрещаем выполнение PHP файлов в storage location ~ \.php$ { deny all; return 404; } # Разрешаем доступ к статическим файлам try_files $uri =404; # Запрещаем листинг директорий autoindex off; } # Запрет прямого доступа к internal storage paths (в обход symlink) location ~ ^/storage/app/(?!public) { deny all; return 404; } # ============================================ # VIKON: OAuth callback redirect (index.php) # ============================================ location = /vikon_core/update/index.php { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass app:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_buffers 16 16k; fastcgi_buffer_size 32k; fastcgi_param REQUEST_SCHEME https; fastcgi_param HTTPS On; } # ============================================ # PHP-FPM: ТОЛЬКО /index.php как entry point # ============================================ location ~ \.php$ { # КРИТИЧНО: Разрешаем ТОЛЬКО /index.php # Любой другой .php файл (например, shell.php в uploads) — 403 if ($uri !~ ^/index\.php$) { return 403; } try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass app:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_buffers 16 16k; fastcgi_buffer_size 32k; fastcgi_param REQUEST_SCHEME https; fastcgi_param HTTPS On; } location ~ /\.ht { deny all; } # Блок для обновления Let's Encrypt (оставить!) location ^~ /.well-known/acme-challenge/ { root /var/www/certbot; allow all; default_type "text/plain"; } }