# Nginx Configuration for YouTube Clone
# Place this file in: /etc/nginx/sites-available/youtube

server {
    listen 80;
    server_name your-domain.com www.your-domain.com;
    
    # Django project directory
    root /home/fnkjyinw/youtube;
    
    # Main Django application
    location / {
        include proxy_params;
        proxy_pass http://127.0.0.1:8000;
        proxy_read_timeout 300s;
        proxy_connect_timeout 75s;
    }
    
    # Static files
    location /static/ {
        alias /home/fnkjyinw/youtube/static/;
        expires 30d;
        add_header Cache-Control "public, immutable";
    }
    
    # Media files (uploaded videos, images, etc.)
    location /media/ {
        alias /home/fnkjyinw/youtube/media/;
        expires 30d;
        add_header Cache-Control "public";
    }
    
    # Security headers
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";
    add_header X-XSS-Protection "1; mode=block";
    
    # File upload size limit (for large video files)
    client_max_body_size 100M;
    
    # Gzip compression
    gzip on;
    gzip_vary on;
    gzip_min_length 1024;
    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
    
    # Error pages
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /home/fnkjyinw/youtube/static;
    }
}

# SSL Configuration (HTTPS)
# Uncomment this block for SSL support
# server {
#     listen 443 ssl http2;
#     server_name your-domain.com www.your-domain.com;
#     
#     ssl_certificate /path/to/your/certificate.crt;
#     ssl_certificate_key /path/to/your/private.key;
#     ssl_protocols TLSv1.2 TLSv1.3;
#     ssl_ciphers HIGH:!aNULL:!MD5;
#     
#     location / {
#         include proxy_params;
#         proxy_pass http://127.0.0.1:8000;
#         proxy_read_timeout 300s;
#         proxy_connect_timeout 75s;
#     }
# }

# Proxy parameters
proxy_params http {
    proxy_set_header Host $http_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;
}
