mcdanlj
(Michael K Johnson)
16 يوليو 2026، 1:02م
1
خلال الأشهر القليلة الماضية (لا أتذكر بالضبط متى بدأ هذا)، لاحظت أن تكوين nginx الخارجي الخاص بي، كما هو موثق في Add an offline page to display when Discourse is rebuilding or starting up ، لتمرير عنوان IP الحقيقي، يتم تجاهله.
كان هذا التكوين الخارجي لـ nginx يعمل لسنوات:
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Real-IP $remote_addr;
الآن أرى أن كل حركة المرور تُنسب إلى شبكة docker الداخلية في نطاق RFC1918، على النحو التالي:
هذا بالطبع يكسر ميزة “تطبيق هذا العقاب على المستخدمين الآخرين الذين يتشاركون هذا عنوان IP” وجميع الاستخدامات الأخرى لعنوان IP البعيد الحقيقي.
أتوقع أن هذا الأمر قد تم معالجته في مكان ما وأنا فقط أبحث بشكل سيء. لكنني سأقدّر أي إرشادات حول ما قد يكون قد تغير، لأتمكن من التكيف مع ذلك.
pfaffman
(Jay Pfaffman)
16 يوليو 2026، 1:27م
2
أتذكر شيئًا عن هذا مؤخرًا، لكنني لا أجد ذلك أيضًا. يتضمن Handling the "chain of trust" of the end user's real IP - #8 by supermathie رابطًا إلى قالب Cloudflare، والذي أعتقد أنه قد يكون نموذجًا جيدًا.
run:
- file:
path: /etc/nginx/conf.d/outlets/server/real-ip-header.conf
chmod: 644
contents: |
real_ip_header cf-connecting-ip;
- exec:
cmd:
# avoid the trap of specifying both URLs on one curl line; the data might not have a final newline
# print sprintf looks dubious at first, but avoids the problem of "how many times do you backslash a \\\\n"
- curl -s https://www.cloudflare.com/ips-v4/ | awk '{print sprintf("set_real_ip_from %s;", $0)}' > /etc/nginx/conf.d/outlets/server/set-real-ip-from-cloudflare.conf
- curl -s https://www.cloudflare.com/ips-v6/ | awk '{print sprintf("set_real_ip_from %s;", $0)}' >> /etc/nginx/conf.d/outlets/server/set-real-ip-from-cloudflare.conf
إليك ما أفعله ويبدو أنه لا يزال يعمل (اعتبارًا من “Discourse 2026.6.0-latest - GitHub - discourse/discourse: A platform for community discussion. Free, open, simple. · GitHub الإصدار 5c507d8359f4d6e8a5d98780c622d51cedbd9bd7”)
after_bundle_exec:
- replace:
filename: /etc/nginx/conf.d/discourse.conf
from: "types {"
to: |
set_real_ip_from 192.168.1.0/24;
set_real_ip_from 192.168.11.0/24;
set_real_ip_from 172.16.0.0/12;
set_real_ip_from 10.0.0.0/8;
real_ip_recursive on;
real_ip_header X-Forwarded-For;
types {
ربما يكون ذلك مرتبطًا بهذا التعديل: FIX: nginx sample configuration should be setting x-f-f to the end us… · discourse/discourse@b4a3389 · GitHub
قد يساعدك هذا:
الخلفية
يجب أن يكون نظام Discourse على دراية بعنوان IP الحقيقي للمستخدم النهائي.
ومع ذلك، لا يتصل المستخدم النهائي مباشرةً بـ Discourse لأن هناك دائمًا خادم ويب واحد أو أكثر في المراحل السابقة (nginx يعمل داخل حاوية Discourse). لذلك، نحتاج إلى طريقة لنقل هذه المعلومات إلى Discourse بطريقة موثوقة.
تُعدّ رسالة x-forwarded-for هي الحل. في هذا الموضوع، سأصف الآليات المحددة للتعامل مع هذه المعلومات بشكل صحيح وكيفية توقعنا لنشرها.
القوالب
تم تحديث القوالب المختلفة للثقة في الوكلاء الوسيدين (مثل clo…
mcdanlj
(Michael K Johnson)
16 يوليو 2026، 3:16م
4
كما هو الحال دائمًا، يساعدني نشر الموضوع ورؤية الردود في العثور على مواضيع مماثلة أخرى. على سبيل المثال
Hi,
I have researched quite a lot but nothing seems to work with me.
I have a discourse setup installed. And I have this remote reverse proxy server that acts as a HTTPS layer between the user and the main discourse server..
[image]
I have included these revers proxy settings properly.. But why does it still show my Reverse Proxy server’s IP Address (hostname to be specific)
[image]
شكرًا لكم جميعًا! سأقوم الآن بإعداد set_real_ip_from في حاوية nginx!
سأقوم بتغطية كامل نطاق RFC1918. ولإفادة الآخرين، سيكون ذلك كالتالي:
after_bundle_exec:
- replace:
filename: /etc/nginx/conf.d/discourse.conf
from: "types {"
to: |
set_real_ip_from 192.168.0.0/16;
set_real_ip_from 172.16.0.0/12;
set_real_ip_from 10.0.0.0/8;
real_ip_recursive on;
real_ip_header X-Forwarded-For;
types {
mcdanlj
(Michael K Johnson)
16 يوليو 2026، 5:07م
5
هذا لا يعمل بالنسبة لي.
أدرك الآن السبب وراء توقف عمله عندي في الالتزام المرجع؛ فقد كسر استبدال set_real_ip الذي كان لديّ لسنوات. المبرر لجعله أكثر متانة معقول، وهذه طريقة أفضل؛ تغيير واحد كاسر ثم يجب أن يكسر أقل في المستقبل.
لا أعرف لماذا لا يتم تطبيق استبدال after_bundle_exec، لكنني سأنتقل إلى إسقاط الملفات.
هذا يعمل بالنسبة لي؛ مشاركة للشخص التالي:
run:
- file:
path: /etc/nginx/conf.d/outlets/server/real-ip-recursive.conf
chmod: 644
contents: |
real_ip_recursive on;
- file:
path: /etc/nginx/conf.d/outlets/server/real-ip-header.conf
chmod: 644
contents: |
real_ip_header X-Forwarded-For;
- file:
path: /etc/nginx/conf.d/outlets/server/set-real-ip-from.conf
chmod: 644
contents: |
set_real_ip_from 192.168.0.0/16;
set_real_ip_from 172.16.0.0/12;
set_real_ip_from 10.0.0.0/8;