Files
smartsoltech_site/nginx-smartsoltech.conf
Andrew K. Choi a70ee08821 🔧 Fix static files serving in Nginx
CRITICAL FIX: Static files (CSS/JS) not loading after changing web:8000 to localhost:8000

Changes:
- nginx-smartsoltech.conf: Enabled /static/ and /media/ locations BEFORE location /
- NGINX_SETUP.md: Updated config to serve static files directly from filesystem
- NGINX_STATIC_FIX.md: Comprehensive troubleshooting guide for static files issues

Why this matters:
- Nginx must serve /static/ and /media/ DIRECTLY from filesystem (fast)
- NOT proxy to Django (slow)
- Order matters: location /static/ MUST be before location /
- Improves performance: 50-100ms → 1-5ms per static file request

Solution on server:
1. git pull origin master
2. sudo cp nginx-smartsoltech.conf /etc/nginx/sites-available/smartsoltech
3. sudo nginx -t && sudo systemctl reload nginx
2025-11-24 11:54:54 +09:00

91 lines
2.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

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.

# SmartSolTech Nginx Configuration
# Скопировать в: /etc/nginx/sites-available/smartsoltech
# Редирект с www на non-www
server {
listen 80;
listen [::]:80;
server_name www.smartsoltech.kr;
return 301 https://smartsoltech.kr$request_uri;
}
# HTTP → HTTPS редирект
server {
listen 80;
listen [::]:80;
server_name smartsoltech.kr;
# Let's Encrypt challenge
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
location / {
return 301 https://$server_name$request_uri;
}
}
# HTTPS конфигурация
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name smartsoltech.kr;
# SSL сертификаты (раскомментировать после получения от Let's Encrypt)
# ssl_certificate /etc/letsencrypt/live/smartsoltech.kr/fullchain.pem;
# ssl_certificate_key /etc/letsencrypt/live/smartsoltech.kr/privkey.pem;
# ssl_trusted_certificate /etc/letsencrypt/live/smartsoltech.kr/chain.pem;
# SSL настройки
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
# Security headers
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;
add_header X-XSS-Protection "1; mode=block" always;
# Максимальный размер загружаемых файлов
client_max_body_size 100M;
# Логи
access_log /var/log/nginx/smartsoltech_access.log;
error_log /var/log/nginx/smartsoltech_error.log;
# Статические файлы - ВАЖНО: должны быть ПЕРЕД location /
location /static/ {
alias /opt/smartsoltech_site/smartsoltech/staticfiles/;
expires 30d;
add_header Cache-Control "public, immutable";
access_log off;
}
# Медиа файлы
location /media/ {
alias /opt/smartsoltech_site/smartsoltech/media/;
expires 7d;
add_header Cache-Control "public";
access_log off;
}
# Прокси к Django приложению
location / {
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_redirect off;
proxy_buffering off;
# Таймауты
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}
}