Files
smartsoltech_site/setup-nginx.sh
Andrew K. Choi b93ab4d796 🌐 Add Nginx configuration and setup scripts
- Added nginx-smartsoltech.conf: Ready-to-use Nginx config with SSL, proxy, security headers
- Added setup-nginx.sh: Automated Nginx setup script with symlink creation
- Added NGINX_SETUP.md: Comprehensive Nginx setup guide with troubleshooting
- Added NGINX_QUICK_SETUP.md: Quick reference cheatsheet

Features:
- HTTP to HTTPS redirect
- www to non-www redirect
- Proxy to Django (localhost:8000)
- SSL configuration (ready for Let's Encrypt)
- Security headers (HSTS, XSS, etc)
- Logging configuration
- Automated default removal and symlink creation
2025-11-24 11:49:52 +09:00

129 lines
4.8 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
###############################################################################
# SmartSolTech Nginx Setup Script
# Автоматическая настройка Nginx с симлинком
###############################################################################
set -e
# Цвета
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo -e "${BLUE}🌐 SmartSolTech Nginx Setup${NC}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
# Проверка прав root
if [[ $EUID -ne 0 ]]; then
echo -e "${RED}❌ Этот скрипт должен быть запущен с правами root${NC}"
echo " Используйте: sudo $0"
exit 1
fi
# Проверка наличия Nginx
if ! command -v nginx &> /dev/null; then
echo -e "${YELLOW}⚠️ Nginx не установлен. Установить? (y/N):${NC}"
read -p "" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo -e "${BLUE}📦 Установка Nginx...${NC}"
apt update
apt install -y nginx
echo -e "${GREEN}✅ Nginx установлен${NC}"
else
echo -e "${RED}❌ Nginx требуется для продолжения${NC}"
exit 1
fi
fi
# Проверка наличия конфига
if [[ ! -f /etc/nginx/sites-available/smartsoltech ]]; then
echo -e "${RED}❌ Файл /etc/nginx/sites-available/smartsoltech не найден${NC}"
echo ""
echo "Создайте его сначала:"
echo " sudo nano /etc/nginx/sites-available/smartsoltech"
echo ""
echo "Или скопируйте из репозитория проекта"
exit 1
fi
echo -e "${BLUE}1/5${NC} Проверка конфигурации smartsoltech..."
if [[ -f /etc/nginx/sites-available/smartsoltech ]]; then
echo -e "${GREEN}✅ Конфигурация найдена${NC}"
else
echo -e "${RED}❌ Конфигурация не найдена${NC}"
exit 1
fi
echo ""
echo -e "${BLUE}2/5${NC} Удаление default конфигурации..."
if [[ -L /etc/nginx/sites-enabled/default ]]; then
rm /etc/nginx/sites-enabled/default
echo -e "${GREEN}✅ Default конфигурация удалена${NC}"
else
echo -e "${YELLOW} Default конфигурация уже удалена${NC}"
fi
echo ""
echo -e "${BLUE}3/5${NC} Создание симлинка..."
if [[ -L /etc/nginx/sites-enabled/smartsoltech ]]; then
echo -e "${YELLOW} Симлинк уже существует, пересоздаём...${NC}"
rm /etc/nginx/sites-enabled/smartsoltech
fi
ln -s /etc/nginx/sites-available/smartsoltech /etc/nginx/sites-enabled/
echo -e "${GREEN}✅ Симлинк создан${NC}"
# Проверка симлинка
echo ""
echo "Проверка симлинка:"
ls -la /etc/nginx/sites-enabled/smartsoltech
echo ""
echo -e "${BLUE}4/5${NC} Проверка конфигурации Nginx..."
if nginx -t; then
echo -e "${GREEN}✅ Конфигурация Nginx корректна${NC}"
else
echo -e "${RED}❌ Ошибка в конфигурации Nginx${NC}"
echo "Проверьте файл: /etc/nginx/sites-available/smartsoltech"
exit 1
fi
echo ""
echo -e "${BLUE}5/5${NC} Перезагрузка Nginx..."
systemctl reload nginx
if systemctl is-active --quiet nginx; then
echo -e "${GREEN}✅ Nginx перезагружен и работает${NC}"
else
echo -e "${RED}❌ Nginx не запущен${NC}"
echo "Проверьте статус: sudo systemctl status nginx"
exit 1
fi
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo -e "${GREEN}🎉 Nginx настроен успешно!${NC}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "Активные конфигурации:"
ls -la /etc/nginx/sites-enabled/
echo ""
echo "Проверка работы:"
echo " curl -I http://smartsoltech.kr"
echo " curl -I http://localhost"
echo ""
echo "Логи:"
echo " sudo tail -f /var/log/nginx/smartsoltech_access.log"
echo " sudo tail -f /var/log/nginx/smartsoltech_error.log"
echo ""
echo "Для получения SSL сертификата:"
echo " sudo certbot --nginx -d smartsoltech.kr -d www.smartsoltech.kr"
echo ""