No, it isn’t an IP address, and that’s the problem. If you’ve got a proxy that’s including a port number in what’s supposed to be an IP address, then the proxy is broken, and you’ll want to get that fixed.
I haven’t find the root cause yet. But I find a defected solution. By adding the following configuration in app.yml. I make the input of ip_address valid.
filename: /etc/nginx/conf.d/discourse.conf
from: $proxy_add_x_forwarded_for
to: $http_your_original_ip_header
global: true
The defected part is that the user ip_addresses are all 127.0.0.1 now. It’s not perfect, but the 500 errors won’t throw finally.
The “for” parameter is used to disclose information about the client
that initiated the request and subsequent proxies in a chain of
proxies. When proxies choose to use the “for” parameter, its default
configuration SHOULD contain an obfuscated identifier as described in
Section 6.3. If the server receiving proxied requests requires some
address-based functionality, this parameter MAY instead contain an IP
address (and, potentially, a port number). A third option is the
“unknown” identifier described in Section 6.2.
If your nginx setting is using $proxy_add_x_forwarded_for as the indicate of user ip. I think ip with port will be a valid input here. You may need to strip the port info out.
Q. Does Application Gateway support x-forwarded-for headers?
Yes, Application Gateway inserts x-forwarded-for, x-forwarded-proto, and x-forwarded-port headers into the request forwarded to the backend. The format for x-forwarded-for header is a comma-separated list of IP:Port. The valid values for x-forwarded-proto are http or https. X-forwarded-port specifies the port at which the request reached at the Application Gateway.
I will seek solution in rack or Azure Gateway.
Thanks @sam also.
Just to add to the conversation - this is standard practice in Azure Application Gateways, and it’s infuriating. They add the port to the forwarded-for header even though they also send it in the forwarded port header.
Two feedback/change requests on Microsoft which you can vote for;
Our “fix” is also the same as the above step, we’re manually setting the forwarded-for header to a generic ip as this caused lots of issues with users being logged out or the site not working properly.
Just out of interest, we are using a httpd redirect within the network, does anyone know if it is possible to rewrite the header and remove the port? Failing that can it be done in nginx (I am unfamiliar with nginx)?
I would look at submitting a PR if we get this fixed but the comments above seem to suggest the devs would prefer this fixing upstream - is that the case?
نعم، بالنسبة لنا، كان الترقية إلى الإصدار 2 تستحق العناء فور توفرها لأحمال العمل الإنتاجية. تقوم بوابات Azure بأشياء غريبة كثيرة، مثل إرفاق المنافذ بعناوين IP في رأس X-Forwarded-For، وهي مجرد واحدة من الأمور ذات التوجه الشخصي التي أزعجتنا. عناوين VIP الثابتة رائعة.
توسع سعة البوابة تلقائيًا أمر رائع أيضًا، وقد أنقذنا مرة أو مرتين بالفعل. كما أن التكرار عبر المناطق (Zone Redundancy) أخيرًا موضع ترحيب كبير.
استغرقت عملية الهجرة حوالي عشرين دقيقة، ولدينا مئات المستمعين وبعض مجموعات الخلفيات (back pools) المعقدة نسبيًا. يوجد سكريبت PowerShell لمساعدتك، وهو بسيط للغاية.
غير متأكد مما إذا كنت تستخدم الشهادات على البوابة، ولكن إذا كنت تستخدمها، فإن الإصدار 2 سريع جدًا - فلا داعي للانتظار 40 دقيقة لتطبيق شهادة، فأصبح الأمر يستغرق ثوانٍ الآن.
التسعير أكثر تعقيدًا بكثير (مايكروسوفت تعطي بيد وتأخذ باليد الأخرى دائمًا)، ولكن بالنسبة لنا، حتى الآن، كانت الفواتير نفسها أو أقل.
حظًا سعيدًا. بسبب التكلفة الأعلى، اضطررنا إلى العودة إلى SKU V1 فور انتهاء النسخة التجريبية من V2.
على أي حال، يبدو أن هذه المشكلة/الحالة قد تم معالجتها مسبقًا عبر طلب دمج مدمج ويجب أن يكون مدرجًا منذ إصدار rack 2.0. لكن وفقًا لـ هذه المشكلة، لا يزال غير موجود في الإصدارات الحالية.
مؤقتًا، أقوم بتطبيق تصحيح أثناء عملية CI/CD للتعامل مع هذه المشكلة. ليس مثاليًا، لكنه يؤدي الغرض حتى نرى الإصلاح في إصدار rack/دسكروس القادم.
إذا كان أي شخص مهتمًا، فهذا هو الجزء الذي تحتاج إلى تعديله للتخلص من المنفذ الإضافي في lib/auth/default_current_user_provider.rb:
if current_user && should_update_last_seen?
u = current_user
ip_port_split = request.ip.split(':')
ip_only = ip_port_split.first
Scheduler::Defer.later "Updating Last Seen" do
u.update_last_seen!
u.update_ip_address!(ip_only)
end
end
لا أعرف ما إذا كانت فكرة جيدة استبدال أي ظهور لـ request.ip بهذا الإصلاح السريع في أي مكان آخر في هذا الملف أو ملفات أخرى (email_controller.rb، 006-mini_profiler.rb، request_tracker.rb)، لكنه يعمل بالنسبة لنا.
كما قلنا، تطبيقه كـ patch أثناء عمليات البناء/CI يحافظ على نظافة قاعدة الكود وقابليتها للتحديث.