diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index e87ac8c3..46e1fc1e 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -63,8 +63,12 @@ services: - ./keys:/keys:ro env_file: .env ports: - - "2020:2020" # WS للسائقين — عام - # 2021 داخلي فقط: الباك إند يناديه عبر http://socket_driver:2021 + # ‏لا نفتح 2020 للعالم مباشرة: Workerman يتكلم نصاً صريحاً، والتطبيق يطلب + # ‏TLS على هذا المنفذ (‎https://…:2020‎) فتتجمّد المصافحة وينتهي بـ timeout. + # ‏nginx على المضيف يستمع على 2020 بالشهادة ويمرّر إلى 12020 هنا. + # ‏انظر nginx/siro-sockets-tls.conf + - "127.0.0.1:12020:2020" + # ‏و2021 داخلي فقط: الباك إند يناديه عبر http://socket_driver:2021 depends_on: - redis mem_limit: 768m @@ -84,7 +88,9 @@ services: - ./keys:/keys:ro env_file: .env ports: - - "3030:3030" + # ‏نفس منطق سوكيت السائقين: nginx على المضيف يستمع على 3030 بالشهادة + # ‏ويمرّر إلى 13030 هنا. و3031 داخلي فقط (http://socket_passenger:3031). + - "127.0.0.1:13030:3030" depends_on: - redis mem_limit: 512m diff --git a/docker/nginx/siro-sockets-tls.conf b/docker/nginx/siro-sockets-tls.conf new file mode 100644 index 00000000..3b98809e --- /dev/null +++ b/docker/nginx/siro-sockets-tls.conf @@ -0,0 +1,106 @@ +# ══════════════════════════════════════════════════════════════════ +# ‏إنهاء TLS أمام سوكيتات Workerman +# ══════════════════════════════════════════════════════════════════ +# ‏يُنسَخ على **المضيف** لا داخل الحاويات: +# /etc/nginx/sites-enabled/siro-sockets-tls.conf +# +# ‏المشكلة التي يحلّها: حاويتا السوكيت تفتحان المنفذين نصاً صريحاً +# (‏new SocketIO(2020)‎ و ‎new SocketIO(3030)‎ بلا سياق SSL)، بينما +# ‏التطبيقان يطلبان ‎https://jordan-siro.intaleqapp.com:2020‎ و ‎:3030‎. +# ‏مصافحة TLS ضد منفذ لا يتكلم TLS تتجمّد حتى المهلة، فيظهر في اللوج: +# Socket Connect Error: timeout +# +# ‏الحل: الحاويتان تُنشران على 127.0.0.1 فقط (12020 / 13030 — انظر +# ‏docker-compose.yml)، و nginx هنا يستمع على 2020 / 3030 بشهادة الدومين +# ‏ويمرّر إليهما مع ترقية WebSocket. النتيجة: روابط التطبيقين تبقى كما هي +# ‏بلا أي بناء جديد، والـ JWT في الـ query string يبقى داخل نفق TLS. +# ══════════════════════════════════════════════════════════════════ + +# ‏اسم مميّز يتفادى التضارب مع أي map باسم ‎$connection_upgrade‎ قد يكون +# ‏CloudPanel معرِّفه أصلاً في سياق http. +map $http_upgrade $siro_connection_upgrade { + default upgrade; + '' close; +} + +# ── سوكيت السائقين — GPS ───────────────────────────────────────── +server { + listen 2020 ssl; + listen [::]:2020 ssl; + http2 on; + + server_name jordan-siro.intaleqapp.com; + + # ‏عدّل المسارين إن كانت شهادتك في مكان آخر — تحقّق بالأمر: + # grep -rh ssl_certificate /etc/nginx/sites-enabled/ | sort -u + ssl_certificate /etc/nginx/ssl-certificates/jordan-siro.intaleqapp.com.crt; + ssl_certificate_key /etc/nginx/ssl-certificates/jordan-siro.intaleqapp.com.key; + + ssl_protocols TLSv1.2 TLSv1.3; + ssl_session_cache shared:SiroSock:10m; + ssl_session_timeout 1d; + + # ‏لا سجلّ وصول: نبضات GPS تصل كل ثوانٍ وتُغرق القرص + access_log off; + error_log /var/log/nginx/siro-socket-driver-error.log warn; + + location / { + proxy_pass http://127.0.0.1:12020; + + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $siro_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; + + # ‏اتصال السائق يعيش ساعات وهو أونلاين — بلا هذه المهل يقطعه nginx + # ‏كل 60 ثانية فتدخل الحاوية في حلقة إعادة اتصال دائمة. + proxy_connect_timeout 10s; + proxy_send_timeout 3600s; + proxy_read_timeout 3600s; + + # ‏التخزين المؤقّت يُعطّل الدفع الفوري في WebSocket + proxy_buffering off; + } +} + +# ── سوكيت الركاب — حالة الرحلة وموقع السائق ────────────────────── +server { + listen 3030 ssl; + listen [::]:3030 ssl; + http2 on; + + server_name jordan-siro.intaleqapp.com; + + ssl_certificate /etc/nginx/ssl-certificates/jordan-siro.intaleqapp.com.crt; + ssl_certificate_key /etc/nginx/ssl-certificates/jordan-siro.intaleqapp.com.key; + + ssl_protocols TLSv1.2 TLSv1.3; + ssl_session_cache shared:SiroSock:10m; + ssl_session_timeout 1d; + + access_log off; + error_log /var/log/nginx/siro-socket-passenger-error.log warn; + + location / { + proxy_pass http://127.0.0.1:13030; + + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $siro_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_connect_timeout 10s; + proxy_send_timeout 3600s; + proxy_read_timeout 3600s; + + proxy_buffering off; + } +}