502 بوابة خاطئة - nginx/1.14.0 (Ubuntu): تعذر العثور على الصورة محليًا + استجابة خطأ من المخدم

مؤخرًا قمت بنقل خادم Dell الخاص بي من موقع إلى آخر. نظام التشغيل الرئيسي/مدير الآلات الافتراضية هو Proxmox VE 5.3. لدي آلة افتراضية تعمل بنظام Nginx تقوم بعكس التوجيه (Reverse Proxy) لعدة آلات افتراضية أخرى، إحداها هي آلة Discourse الافتراضية.

بعد إعداد الموجه (Router) الجديد، تمكنت من توصيل عدة من آلاتي الافتراضية بالإنترنت (دون الحاجة حتى إلى تجديد شهادات SSL). ومع ذلك، عند محاولة الوصول إلى Discourse عبر المتصفح، أتحصل على رسالة خطأ 502 Bad Gateway - nginx/1.14.0 (Ubuntu).

لقد تلقيت هذا الخطأ من قبل، ولكن عادة ما يتم حله بإحدى الطرق التالية:

إعادة تشغيل آلة Discourse الافتراضية

لا يزال الخطأ 502 Bad Gateway - nginx/1.14.0 (Ubuntu) يظهر في المتصفح.

مسح ملفات تعريف الارتباط (Cookies) في المتصفح وتجربة متصفحات مختلفة

فقط في حال كانت المشكلة من جهتي… لا. نفس الخطأ 502 Bad Gateway - nginx/1.14.0 (Ubuntu) يظهر في متصفحات مختلفة.

تنظيف Discourse وفحص مساحة القرص

في البداية، عند التنظيف، تم حذف حوالي 4 جيجابايت من البيانات. لقد فوجئت جدًا. ربما كان هذا هو السبب في المشكلة من الأساس؟ على أي حال، الآن عندما أحاول تنظيف Discourse:

> root@forum:/var/discourse# ./launcher cleanup
> WARNING! This will remove all stopped containers.
> Are you sure you want to continue? [y/N] y
> Total reclaimed space: 0B
> WARNING! This will remove all images without at least one container associated to them.
> Are you sure you want to continue? [y/N] y
> Total reclaimed space: 0B

أود أيضًا التأكيد على أنني ليست نفدت مساحة القرص:

سحب Git

النظام محدث.

> root@forum:/var/discourse# git pull
> Already up to date.

إعادة تشغيل Discourse

هنا اكتشفت خطأين أحصل عليهما:

> root@forum:/var/discourse# ./launcher restart app
> 
> WARNING: We are about to start downloading the Discourse base image
> This process may take anywhere between a few minutes to an hour, depending on your network speed
> 
> Please be patient
> 
> Unable to find image 'discourse/base:2.0.20191013-2320' locally
> /usr/bin/docker: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
> See '/usr/bin/docker run --help'.
> Your Docker installation is not working correctly
> 
> See: `https://meta.discourse.org/t/docker-error-on-bootstrap/13657/18?u=sam`

راجعت الرابط المقترح. يوصي الرابط بإجراء سحب Git و إعادة بناء Discourse (وسترى ما أحصل عليه لاحقًا أدناه). كما يقترح تشغيل أمر Docker “Hello World”. يعمل الأمر (على الرغم من أنه يبدو أن هناك بعض المشاكل؟):

> root@forum:/var/discourse# docker run -it --rm hello-world
> Unable to find image 'hello-world:latest' locally
> latest: Pulling from library/hello-world
> 1b930d010525: Pull complete
> Digest: sha256:c3b4ada4687bbaa170745b3e4dd8ac3f194ca95b2d0518b417fb47e5879d9b5f
> Status: Downloaded newer image for hello-world:latest
> 
> Hello from Docker!
> This message shows that your installation appears to be working correctly.
> 
> To generate this message, Docker took the following steps:
>  1. The Docker client contacted the Docker daemon.
>  2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
>     (amd64)
>  3. The Docker daemon created a new container from that image which runs the
>     executable that produces the output you are currently reading.
>  4. The Docker daemon streamed that output to the Docker client, which sent it
>     to your terminal.
> 
> To try something more ambitious, you can run an Ubuntu container with:
>  $ docker run -it ubuntu bash
> 
> Share images, automate workflows, and more with a free Docker ID:
>  https://hub.docker.com/
> 
> For more examples and ideas, visit:
>  https://docs.docker.com/get-started/
> 
> failed to resize tty, using default size

حسنًا، جربت بعد ذلك Ubuntu Bash … وظهر خطأ:

> root@forum:/var/discourse# docker run -it ubuntu bash
> Unable to find image 'ubuntu:latest' locally
> docker: Error response from daemon: Get https://registry-1.docker.io/v2/library/ubuntu/manifests/latest: Get https://auth.docker.io/token?scope=repository%3Alibrary%2Fubuntu%3Apull&service=registry.docker.io: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
> See 'docker run --help'.

حان الوقت للانتقال إلى بعض الطرق الأخرى التي أعرفها:

إيقاف وتشغيل Discourse

أحصل على نفس النتيجة كما في حالة إعادة التشغيل:

> root@forum:/var/discourse# ./launcher stop app
> 
> WARNING: We are about to start downloading the Discourse base image
> This process may take anywhere between a few minutes to an hour, depending on your network speed
> 
> Please be patient
> 
> Unable to find image 'discourse/base:2.0.20191013-2320' locally
> /usr/bin/docker: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
> See '/usr/bin/docker run --help'.
> Your Docker installation is not working correctly
> 
> See: `https://meta.discourse.org/t/docker-error-on-bootstrap/13657/18?u=sam`
> 
> root@forum:/var/discourse# ./launcher start app
> 
> WARNING: We are about to start downloading the Discourse base image
> This process may take anywhere between a few minutes to an hour, depending on your network speed
> 
> Please be patient
> 
> Unable to find image 'discourse/base:2.0.20191013-2320' locally
> /usr/bin/docker: Error response from daemon: Get https://registry-1.docker.io/v2/discourse/base/manifests/2.0.20191013-2320: Get https://auth.docker.io/token?scope=repository%3Adiscourse%2Fbase%3Apull&service=registry.docker.io: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
> See '/usr/bin/docker run --help'.
> Your Docker installation is not working correctly
> 
> See: `https://meta.discourse.org/t/docker-error-on-bootstrap/13657/18?u=sam`

إعادة بناء Discourse

وأحصل على نفس الخطأين مرة أخرى.

> root@forum:/var/discourse# ./launcher rebuild app
> 
> WARNING: We are about to start downloading the Discourse base image
> This process may take anywhere between a few minutes to an hour, depending on your network speed
> 
> Please be patient
> 
> Unable to find image 'discourse/base:2.0.20191013-2320' locally
> /usr/bin/docker: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
> See '/usr/bin/docker run --help'.
> Your Docker installation is not working correctly
> 
> See: https://meta.discourse.org/t/docker-error-on-bootstrap/13657/18?u=sam

الاستعادة من نسخة احتياطية سابقة

لدي نسخة (Snapshot) من وقت قبل نقل الخادم وإجراء التنظيف (والذي، كما ذكرت، حذف حوالي 4 جيجابايت من الملفات). جربت كل ما سبق مرة أخرى … ونفس النتيجة (باستثناء التنظيف)، بالإضافة إلى 502 Bad Gateway - nginx/1.14.0 (Ubuntu) في المتصفح. إذن ربما لا علاقة لهذا بالتنظيف؟

في كل وقت قضيتُه مع Discourse، لم أواجه أيًا من هذين الخطأين من قبل. هل لديك أي اقتراحات حول ما يمكنني فعله لحل هذه الأخطاء وجعل Discourse يعمل في المتصفح؟

لا يمكن لخادمك الاتصال بـ Docker Hub لتحميل الصور الكبيرة، وقد نجح فقط تحميل صورة hello world الصغيرة.

فكيف يمكنني معالجة هذا؟ ليس لدي الكثير من الخبرة في استخدام Docker، لذا لا أعرف من أين أبدأ.

الشيء الوحيد في Docker الذي أعرفه هو الأوامر التي تتضمنها تثبيت Discourse (إلى جانب التعديلات بالطبع، حيث يتم تثبيت Discourse على آلة افتراضية على خادم خاص بي بدلاً من سحابة تابعة لطرف ثالث).

ما إصدار Docker الذي تعمل به (docker info

هل يمكنك التحقق من مكدس الشبكة الخاص بك لمعرفة ما إذا كانت هناك مشاكل في إنشاء اتصالات إلى https://registry-1.docker.io/v2/؟

إليك معلومات Docker الخاصة بي:

root@forum:/var/discourse# docker info
Containers: 1
Running: 1
Paused: 0
Stopped: 0
Images: 3
Server Version: 18.09.5
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: bb71b10fd8f58240ca47fbb579b9d1028eea7c84
runc version: 2b18fe1d885ee5083ef9f0838fee39b62d653e30
init version: fec3683
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 4.15.0-69-generic
Operating System: Ubuntu 18.04.2 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 6.805GiB
Name: forum
ID: 2RRX:ZQIT:R5AK:WNPR:VJ6Z:2EBY:PFOL:W5RD:GL3X:RUQM:YLJ4:2L2X
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Product License: Community Engine

WARNING: No swap limit support

أما بخصوص سؤالك:

كيف أقوم بذلك؟

@Falco إذن، لقد حاولت استكشاف هذه المشكلة وحلها بشكل أعمق، وأصبحت الآن أكثر حيرة من قبل. الأخبار الجيدة والسيئة:

الأخبار الجيدة

بعد إجراء عدة عمليات إعادة بناء لـ Discourse (./launcher rebuild app)، لم أعد أواجه أخطاء Unable to find image أو Error response from daemon! عند بدء تشغيل أو إعادة تشغيل Discourse، لا أرى أي أخطاء:

> root@forum:/var/discourse# ./launcher start app
> 
> .+ /usr/bin/docker run --shm-size=512m -d --restart=always -e LANG=en_US.UTF-8 -e RAILS_ENV=production -e UNICORN_WORKERS=4 -e UNICORN_SIDEKIQS=1 -e RUBY_GLOBAL_METHOD_CACHE_SIZE=131072 -e RUBY_GC_HEAP_GROWTH_MAX_SLOTS=40000 -e RUBY_GC_HEAP_INIT_SLOTS=400000 -e RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR=1.5 -e DISCOURSE_DB_SOCKET=/var/run/postgresql -e DISCOURSE_DB_HOST= -e DISCOURSE_DB_PORT= -e DISCOURSE_HOSTNAME=discourse.example.com -e DISCOURSE_DEVELOPER_EMAILS=admin@example.com,postmaster@example.com -e DISCOURSE_SMTP_ADDRESS=smtp.sparkpostmail.com -e DISCOURSE_SMTP_PORT=587 -e DISCOURSE_SMTP_USER_NAME=SMTP_Injection -e DISCOURSE_SMTP_PASSWORD=<HIDING-FOR-PRICACY> -e LETSENCRYPT_ACCOUNT_EMAIL=admin@example.com -h forum-app -e DOCKER_HOST_IP=100.17.0.1 --name app -t -p 8080:80 -p 8443:443 -p 2222:22 -v /var/discourse/shared/standalone:/shared -v /var/discourse/shared/standalone/log/var-log:/var/log --mac-address 02:96:f3:e6:e7:14 local_discourse/app /sbin/boot
> cebe89493bc79dab2c1716599629adfe3dc571c8659367e6ffa0d39b0e6d47af
> root@forum:/var/discourse# ./launcher restart app
> .+ /usr/bin/docker stop -t 10 app
> app
> 
> starting up existing container
> .+ /usr/bin/docker start app
> app

Docker قيد التشغيل أيضًا:
> root@forum:/var/discourse# systemctl status docker.service
> ● docker.service - Docker Application Container Engine
>    Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
>    Active: active (running) since Thu 2019-11-14 03:00:54 UTC; 17h ago
>      Docs: https://docs.docker.com
>  Main PID: 18721 (dockerd)
>     Tasks: 31
>    CGroup: /system.slice/docker.service
>            ├─ 1375 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8443 -container-ip 172.17.0.2 -container-port 443
>            ├─ 1387 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8080 -container-ip 172.17.0.2 -container-port 80
>            ├─ 1399 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 2222 -container-ip 172.17.0.2 -container-port 22
>            └─18721 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
> 
> Nov 14 20:13:26 forum dockerd[18721]: time="2019-11-14T20:13:26.430856242Z" level=info msg="ignoring event" module=libcontainerd namespace=moby topic=/tasks/delete type="*events.TaskDelete"
> Nov 14 20:13:28 forum dockerd[18721]: time="2019-11-14T20:13:28.597999379Z" level=info msg="ignoring event" module=libcontainerd namespace=moby topic=/tasks/delete type="*events.TaskDelete"
> Nov 14 20:13:30 forum dockerd[18721]: time="2019-11-14T20:13:30.862158413Z" level=info msg="ignoring event" module=libcontainerd namespace=moby topic=/tasks/delete type="*events.TaskDelete"
> Nov 14 20:13:32 forum dockerd[18721]: time="2019-11-14T20:13:32.978285148Z" level=info msg="ignoring event" module=libcontainerd namespace=moby topic=/tasks/delete type="*events.TaskDelete"
> Nov 14 20:13:35 forum dockerd[18721]: time="2019-11-14T20:13:35.105130149Z" level=info msg="ignoring event" module=libcontainerd namespace=moby topic=/tasks/delete type="*events.TaskDelete"
> Nov 14 20:13:37 forum dockerd[18721]: time="2019-11-14T20:13:37.151466214Z" level=info msg="ignoring event" module=libcontainerd namespace=moby topic=/tasks/delete type="*events.TaskDelete"
> Nov 14 20:13:39 forum dockerd[18721]: time="2019-11-14T20:13:39.024948159Z" level=info msg="ignoring event" module=libcontainerd namespace=moby topic=/tasks/delete type="*events.TaskDelete"
> Nov 14 20:14:05 forum dockerd[18721]: time="2019-11-14T20:14:05.179759938Z" level=info msg="ignoring event" module=libcontainerd namespace=moby topic=/tasks/delete type="*events.TaskDelete"
> Nov 14 20:14:16 forum dockerd[18721]: time="2019-11-14T20:14:16.078334393Z" level=info msg="Container cebe89493bc79dab2c1716599629adfe3dc571c8659367e6ffa0d39b0e6d47af failed to exit within
> Nov 14 20:14:16 forum dockerd[18721]: time="2019-11-14T20:14:16.281731176Z" level=info msg="ignoring event" module=libcontainerd namespace=moby topic=/tasks/delete type="*events.TaskDelete"

الأخبار السيئة

ما زلت أتلقى خطأ 502 Bad Gateway - nginx/1.14.0 (Ubuntu) عند محاولة فتح الموقع في متصفحات مختلفة. لقد قمت بمسح ذاكرة التخزين المؤقت الخاصة بها وحاولت استخدام متصفحات متعددة للتأكد. لا فائدة.

لاحظت شيئًا واحدًا: إذا حاولت إجراء تنظيف لـ Discourse، فإنه يمسح عددًا كبيرًا من الحاويات:

> root@forum:/var/discourse# ./launcher cleanup
> WARNING! This will remove all stopped containers.
> Are you sure you want to continue? [y/N] y
> Total reclaimed space: 0B
> WARNING! This will remove all images without at least one container associated to them.
> Are you sure you want to continue? [y/N] y
> Deleted Images:
> untagged: hello-world:latest
> untagged: hello-world@sha256:c3b4ada4687bbaa170745b3e4dd8ac3f194ca95b2d0518b417fb47e5879d9b5f
> deleted: sha256:fce289e99eb9bca977dae136fbe2a82b6b7d4c372474c9235adc1741675f587e
> deleted: sha256:af0b15c8625bb1938f1d7b17081031f649fd14e6b233688eea3c5483994a66a3
> untagged: discourse/base:2.0.20191013-2320
> untagged: discourse/base@sha256:77e010342aa5111c8c3b81d80de7d4bdb229793d595bbe373992cdb8f86ef41f
> deleted: sha256:53b44681b65ee5e9a9cadc6bd34c6aa6f6bcbbbe6270e61669c50bcd655c6898
> deleted: sha256:939a3ac6d5627270ae02a9f9ea05c580589cec0afa019b7f296fdd43157dd3a0
> 
> Total reclaimed space: 452.2MB

الآن، كلما حاولت البدء أو إعادة التشغيل… عادت الأخطاء! لقد عدت إلى النقطة التي توقفت فيها رسائل الخطأ Unable to find image أو Error response from daemon عن الظهور. من الواضح أن الحاويات تم إعادة بنائها، وأن مسح صور الحاويات يسبب مشاكل.

إذا كان Docker معطلاً لديك (أي أن أمر docker run ubuntu يفشل)، فمن المؤكد أن Discourse لن يعمل.

للحصول على دعم مخصص لـ Docker، يمكنك محاولة النشر في https://forums.docker.com/

@فالكو نعم، أحصل على أخطاء Unable to find image locally و Error response from daemon كما كنت أحصل عليها سابقًا عند تشغيل هذا الأمر.

لذلك، وبناءً على اقتراحك، لقد بدأت موضوعًا في منتديات Docker. للأسف، لم يتلقَ رد حتى الآن.

إذن، إليك بعض الأخبار الإضافية:

أخبار جيدة

لم أعد أتلقى الرسالة التالية: /usr/bin/docker: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).!

لم يعد الأمر docker run ubuntu يُبلغ عن خطأ. @Falco، هل من المفترض أن أرى أي مخرجات؟

root@forum:/var/discourse# docker run ubuntu
root@forum:/var/discourse#

إذن، ما الذي قمت به لحل هذه المشكلة؟ استبدلت خادم الأسماء (DNS) المستخدم في هذه الآلة الافتراضية بخدمة Google Public DNS:
echo "nameserver 8.8.8.8" > /etc/resolv.conf

لكن يجب عليّ تشغيل الأمر أعلاه في كل مرة بعد إعادة تشغيل الآلة الافتراضية (يبدو أن هذا حل مؤقت)، وإلا سأواجه الخطأين عند محاولة تشغيل أي أوامر ./launcher. بعد ذلك، يظهر خطأ واحد فقط (Unable to find image 'discourse/base:2.0.20191013-2320' locally)، لكن الأمر يبدو أنه يُحل:

root@forum:/var/discourse# ./launcher start app

WARNING: We are about to start downloading the Discourse base image
This process may take anywhere between a few minutes to an hour, depending on your network speed

Please be patient

Unable to find image 'discourse/base:2.0.20191013-2320' locally
2.0.20191013-2320: Pulling from discourse/base
Digest: sha256:77e010342aa5111c8c3b81d80de7d4bdb229793d595bbe373992cdb8f86ef41f
Status: Downloaded newer image for discourse/base:2.0.20191013-2320

starting up existing container
+ /usr/bin/docker start app
app

يبدو أيضًا أن بإمكانني تشغيل ./launcher rebuild app دون أخطاء. إليك آخر ما يظهره مخرج الأمر (مع إخفاء عناوين URLs وعنوان MAC):

+ /usr/bin/docker run --shm-size=512m -d --restart=always -e LANG=en_US.UTF-8 -e RAILS_ENV=production -e UNICORN_WORKERS=4 -e UNICORN_SIDEKIQS=1 -e RUBY_GLOBAL_METHOD_CACHE_SIZE=131072 -e RUBY_GC_HEAP_GROWTH_MAX_SLOTS=40000 -e RUBY_GC_HEAP_INIT_SLOTS=400000 -e RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR=1.5 -e DISCOURSE_DB_SOCKET=/var/run/postgresql -e DISCOURSE_DB_HOST= -e DISCOURSE_DB_PORT= -e DISCOURSE_HOSTNAME=discourse.domain.com -e DISCOURSE_DEVELOPER_EMAILS=admin@domain.com,postmaster@domain.com -e DISCOURSE_SMTP_ADDRESS=smtp.sparkpostmail.com -e DISCOURSE_SMTP_PORT=587 -e DISCOURSE_SMTP_USER_NAME=SMTP_Injection -e DISCOURSE_SMTP_PASSWORD=0d431cd177ce3d35833aa823d498eb57c7c4e99c -e LETSENCRYPT_ACCOUNT_EMAIL=admin@domain.com -h forum-app -e DOCKER_HOST_IP=172.17.0.1 --name app -t -p 8080:80 -p 8443:443 -p 2222:22 -v /var/discourse/shared/standalone:/shared -v /var/discourse/shared/standalone/log/var-log:/var/log --mac-address 00:00:00:00:00:01 local_discourse/app /sbin/boot
abb788d4a6fd301d88f129189a07a19c4a6bfc8554d43c555d3e3cd126374736

أخبار سيئة

ما زلت أحصل على خطأ 502 Bad Gateway - nginx/1.14.0 (Ubuntu) عند محاولة الدخول إلى الصفحة.

ما الذي قد يكون المشكلة؟ هل لديك أي اقتراحات؟

تم حل مشكلتي! يظهر منتدى Discourse الخاص بي الآن في المتصفح!

في الواقع، لحل أكثر دقة، قام فرانسيس داي في منتديات Nginx بحل مشكلتي! كانت المشكلة في Nginx حقًا. إليك ما قمت به:

  1. سجلت الدخول إلى جهاز Nginx الافتراضي (VM) الخاص بي.
  2. فتحت ملف إعدادات Discourse باستخدام VIM: vim /etc/nginx/sites-available/discourse.conf
  3. إليك كيف كان يبدو ملف إعدادات Discourse الخاص بي (بالطبع لم أستخدم اسم النطاق الذي أستخدمه عادةً، حيث 192.168.0.101 = جهاز Nginx الافتراضي و 192.168.0.104 = جهاز Discourse الافتراضي).
  4. قمت بتغيير واحد فقط: غيّرت proxy_pass http://discourse.domainame.com:8080/; إلى proxy_pass 192.168.0.104:8080/;. لذا فإن proxy_pass مضبوط على العنوان المحلي (Local IP) لجهاز Discourse الافتراضي بدلاً من اسم المضيف (Hostname).
  5. حفظت ملف الإعدادات، ثم قمت بإعادة تحميل الخدمة (systemctl reload nginx.service) وإعادة تشغيلها (systemctl restart nginx.service) في Nginx.
  6. رائع! قمت بتحديث رابط Discourse، وظهر الموقع! لم أحتج حتى لإعادة تشغيل أو إعادة بناء Discourse!

آمل أن يجد شخص ما ما كتبته هنا مفيدًا، حيث يمكن أن يكون استخدام Nginx كوسيط عكسي (reverse proxy) لـ Discourse أمرًا معقدًا حقًا.