# ============================================================================
# hamkadr.ir  — for the central "mirror-nginx" container (image nginx:alpine).
#
# Edit the host file:   /root/mirror-server/nginx/nginx.conf
# Paste the two server{} blocks below INTO its http { } block (next to meezi), then:
#   docker exec mirror-nginx nginx -t && docker exec mirror-nginx nginx -s reload
#
# Cert: mirror-nginx only mounts /etc/ssl/{draletaha,meezi,soroushasadi}. /etc/ssl/hamkadr is
# NOT visible inside the container, so place the hamkadr.ir cert under an already-mounted dir:
#   mkdir -p /etc/ssl/soroushasadi/hamkadr
#   cp fullchain.pem  /etc/ssl/soroushasadi/hamkadr/fullchain.pem
#   cp privateKey.pem /etc/ssl/soroushasadi/hamkadr/privateKey.pem
# (Cleaner alternative: add a bind mount /etc/ssl/hamkadr:/etc/ssl/hamkadr to the mirror-server
#  compose and recreate mirror-nginx — but that briefly drops all sites; the subdir avoids that.)
#
# Prereqs: hamkadr.ir + www A → 171.22.25.73 ; app published on host :2569 (docker-compose.yml).
# $connection_upgrade map is already defined globally in this nginx.conf.
# ============================================================================

server {
    listen 80;
    server_name hamkadr.ir www.hamkadr.ir;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    http2 on;
    server_name hamkadr.ir www.hamkadr.ir;
    client_max_body_size 25m;

    ssl_certificate     /etc/ssl/soroushasadi/hamkadr/fullchain.pem;
    ssl_certificate_key /etc/ssl/soroushasadi/hamkadr/privateKey.pem;

    location / {
        proxy_pass http://171.22.25.73:2569;
        proxy_http_version 1.1;
        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;   # app's ForwardedHeaders reads this → HTTPS-aware
        proxy_set_header Upgrade           $http_upgrade;
        proxy_set_header Connection        $connection_upgrade;
    }
}
