This commit is contained in:
99
scripts/setup-nginx.sh
Executable file
99
scripts/setup-nginx.sh
Executable file
@@ -0,0 +1,99 @@
|
||||
#!/bin/bash
|
||||
# scripts/setup-nginx.sh - Настройка nginx для CatLink
|
||||
|
||||
set -e
|
||||
|
||||
echo "⚙️ Настройка nginx конфигурации..."
|
||||
|
||||
# Создание конфигурации nginx
|
||||
sudo tee /etc/nginx/sites-available/links > /dev/null << 'EOF'
|
||||
server {
|
||||
listen 80;
|
||||
server_name links.shareon.kr sharon.kr;
|
||||
|
||||
# Redirect all HTTP requests to HTTPS
|
||||
return 301 https://$server_name$request_uri;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
server_name links.shareon.kr sharon.kr;
|
||||
|
||||
# SSL certificates (will be configured by certbot)
|
||||
# ssl_certificate /etc/letsencrypt/live/links.shareon.kr/fullchain.pem;
|
||||
# ssl_certificate_key /etc/letsencrypt/live/links.shareon.kr/privkey.pem;
|
||||
|
||||
# Modern SSL configuration
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384;
|
||||
ssl_prefer_server_ciphers off;
|
||||
ssl_session_cache shared:SSL:10m;
|
||||
|
||||
# Security headers
|
||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
||||
add_header X-Frame-Options DENY;
|
||||
add_header X-Content-Type-Options nosniff;
|
||||
add_header X-XSS-Protection "1; mode=block";
|
||||
|
||||
# Proxy to frontend (Next.js)
|
||||
location / {
|
||||
proxy_pass http://localhost:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
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_cache_bypass $http_upgrade;
|
||||
proxy_read_timeout 86400;
|
||||
}
|
||||
|
||||
# Proxy API requests to backend (Django)
|
||||
location /api/ {
|
||||
proxy_pass http://localhost:8000;
|
||||
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 admin requests to backend (Django)
|
||||
location /admin/ {
|
||||
proxy_pass http://localhost:8000;
|
||||
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;
|
||||
}
|
||||
|
||||
# Serve static files from Django
|
||||
location /static/ {
|
||||
proxy_pass http://localhost:8000;
|
||||
proxy_set_header Host $host;
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
|
||||
# Serve media files from Django
|
||||
location /media/ {
|
||||
proxy_pass http://localhost:8000;
|
||||
proxy_set_header Host $host;
|
||||
expires 1y;
|
||||
add_header Cache-Control "public";
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
echo "🔗 Активация конфигурации nginx..."
|
||||
sudo ln -sf /etc/nginx/sites-available/links /etc/nginx/sites-enabled/
|
||||
sudo rm -f /etc/nginx/sites-enabled/default
|
||||
|
||||
echo "🧪 Проверка конфигурации nginx..."
|
||||
sudo nginx -t
|
||||
|
||||
echo "🔄 Перезапуск nginx..."
|
||||
sudo systemctl restart nginx
|
||||
sudo systemctl enable nginx
|
||||
|
||||
echo "✅ nginx настройка завершена"
|
||||
Reference in New Issue
Block a user