อนุญาต User-Agent เพียงหนึ่งเดียว บล็อกที่เหลือใน nginx หรือไม่

เพิ่งเคยใช้งานไซต์นี้ ดังนั้นฉันจะสรุปสั้นๆ:

ฉันมี:

    if ($http_user_agent ~* (A-certain-self-made-User-Agent-here)) {
            return 200;
    }

ซึ่งทำงานได้ดีมาก (ทดสอบโดยการสลับ 200 เป็น 403)

คำถามของฉันคือ: มีวิธีใน: /etc/nginx/sites-enabled/default เพื่อให้อนุญาต User-Agent ONE เท่านั้นและปฏิเสธส่วนที่เหลือหรือไม่

ฉันรู้ว่านี่ดูงี่เง่า แต่เป็นสิ่งที่ฉันอยากทำ (ถ้าเป็นไปได้) อาจจะประมาณนี้?:

    if (http_user_agent ~*(user-agent)) {
           return 200;
    else
           return 403;
    }

person Neil Mcdonald    schedule 16.07.2013    source แหล่งที่มา


คำตอบ (3)


ลองสิ่งนี้:

if ($http_user_agent !~* (A-certain-self-made-User-Agent-here)) {
        return 403;
}

นี่ควรเป็น 'ไม่ตรงกัน' ในตัวแทนผู้ใช้ของคุณ ข้อมูลอ้างอิงที่นี่: HttpRewriteModule

person ProfessionalAmateur    schedule 17.07.2013

if ($http_user_agent !~* "A-certain-self-made-User-Agent-here") {
    return 403;
}

กำลังทำงานบนเว็บไซต์ของฉัน

person Vidyut    schedule 19.07.2013

คุณสามารถลองทำสิ่งต่อไปนี้ในตำแหน่งที่เหมาะสม

set $isallowed = "";
if ($http_user_agent = allowed_user_agent) {
    set $isallowed "${isallowed}YES";
}

if ($isallowed !~ YES) {
    rewrite ^ http://yourserver.com permanent;
}
person deagh    schedule 17.07.2013