深入nginx之《获取用户的真实IP》

深入nginx之《获取用户的真实IP》

原创: lee 川西阳光里 今天

获取用户的真实IP

        Nginx会将客户端的IP信息存放在$remote_addr变量里,但这并不意味着它就是客户端的IP,生产环境往往会充满各种代理,让IP的来龙去脉变得扑朔迷离。

        目前互联网公司基本上都采用这种架构方式

        用户的请求并不是直接和Nginx交互,而是通过了CDN加速平台。默认情况下,Nginx看到的$remote_addr是CDN的IP,这对日志的记录和分析,还有后端的业务逻辑都可能产生不良的影响,如果需要获取到用户的真实IP呢,这个时候realip模块就起到了作用。

        此模块需要编译时开启:

        --with-http_realip_module

        在Nginx的HTTP块里面配置:

        set_real_ip_from CDN_IP;

        real_ip_header X-Forwarded-For;

        real_ip_recursive on;

   

     set_real_ip_from

        设置哪些IP是可信任的,从这些IP进行获取请求头信息,这些IP就配置为CDN的IP白名单。

 

    real_ip_header

        定义从哪个请求头获取IP信息,其值将用于替换客户端地址。一般都使用X-Forwarded-For。

 

    real_ip_recursive

        如果启用递归搜索,将会对可信任的IP匹配,原始客户端地址将替换为在请求头域中发送的最后一个不可信地址。如果禁用递归搜索,则从白名单中由real_ip_header指令定义的请求头中的最后一个地址替换。

 

        通过此方式就可以获取到CDN传递给Nginx的用户的IP。那么问题来了,$remote_addr被替换成了用户的IP,有些时候我们也希望获取到CDN 的节点IP,这对于排查一些和CDN有关的问题是由帮助的。可以使用$realip_remote_addr,它可以保留原始客户端地址。 (1.9.7版本新增的变量)


 

Pingbacks已打开。

引用地址

评论
  1. AnnaGal AnnaGal 发布于 2021年1月23日 01:58 #

    <a href="http://buytretinoinretina.com/">can you buy tretinoin online in us</a> <a href="http://prednisoloneprednisone.com/">prednisolone tablets 25mg</a> <a href="http://wellbutrinbupropionpill.com/">wellbutrin prescription canada</a> <a href="http://fildenasildenafil.com/">sildenafil prescription uk</a> <a href="http://levothyroxinesynthroid.com/">synthroid 100 mcg price in india</a>

  2. SamGal SamGal 发布于 2021年1月23日 02:17 #

    <a href="http://phenerganpromethazine.com/">cheap phenergan tablets</a> <a href="http://lasixfurosemidemed.com/">lasix price in india</a> <a href="http://buyazithromycinzithromax.com/">buy azithromycin online fast shipping</a>

  3. Gregoryclelt Gregoryclelt 发布于 2021年1月23日 03:38 #

    buying prescription viagra from canada <a href=" http://genericvgrshop.com/# ">viagra</a>
    pain meds online without doctor prescription http://genericvgrshop.com buy generic viagra here
    <a href=http://genericvgrshop.com/#>buy generic viagra here</a> buy prescription viagra online without

  4. WayneLax WayneLax 发布于 2021年1月23日 03:49 #

    generic viagra without doctor's prescription <a href=" http://genericvgrshop.com/# ">viagra Without a Doctor Prescription</a>
    erectile dysfunction treatments http://genericvgrshop.com buy generic viagra
    <a href=http://genericvgrshop.com/#>generic viagra without doctor's prescription</a> meds online without doctor prescription

  5. Josephsaima Josephsaima 发布于 2021年1月23日 03:54 #

    buying prescription viagra from canada <a href=" http://genericvgrshop.com/# ">meds without a doctor prescription</a>
    pills erectile dysfunction http://genericvgrshop.com generic viagra for sale
    <a href=http://genericvgrshop.com/#>prescription viagra without a doctor</a> buy generic viagra here

  6. IvyGal IvyGal 发布于 2021年1月23日 04:23 #

    <a href="https://oipharmacy.com/">online canadian pharmacy coupon</a> <a href="https://amoxicillindrug.com/">buy augmentin 375 online no prescription</a> <a href="https://doxycyclinerem.com/">doxycycline 40 mg generic</a> <a href="https://indocindrug.com/">indocin 50 mg cap</a> <a href="https://tetracyclinepill.com/">can you buy terramycin over the counter</a> <a href="https://celebrexnsaid.com/">celebrex lowest price</a> <a href="https://wherecialis.com/">tadalafil - generic</a> <a href="https://clomidclomifene.com/">where can i get clomid online in australia</a> <a href="https://trazodonesari.com/">trazodone buy</a> <a href="https://metformindrug.com/">buy glucophage</a> <a href="https://acycloviral.com/">zovirax price uk</a> <a href="https://prednisoloneprednisone.com/">can you buy prednisolone over the counter in australia</a> <a href="https://opcialis.com/">order cialis 20mg</a> <a href="https://levitrart.com/">best pharmacy cheap levitra</a> <a href="https://celexacitaloprampill.com/">brand name citalopram</a>

  7. JamesTab JamesTab 发布于 2021年1月23日 05:00 #

    buy medication without an rx <a href=" http://genericvgrshop.com/# ">generic viagra for sale</a>
    herbal ed remedies http://genericvgrshop.com medications without a doctor's prescription
    <a href=http://genericvgrshop.com/#>buying prescription viagra from canada</a> generic viagra without a doctor prescription

  8. Personal Loans Personal Loans 发布于 2021年1月23日 06:31 #

    <a href="http://pngloans.com/">direct payday loan lenders online</a> <a href="http://wpaloans.com/">loans online payday</a> <a href="http://loandest.com/">no credit check payday loan</a>

  9. WayneLax WayneLax 发布于 2021年1月23日 06:49 #

    medications without a doctor's prescription <a href=" http://genericvgrshop.com/# ">generic viagra for sale</a>
    online ed drugs http://genericvgrshop.com viagra without doctor script
    <a href=http://genericvgrshop.com/#>meds without a doctor prescription</a> buying prescription viagra from canada

  10. JamesTab JamesTab 发布于 2021年1月23日 07:19 #

    medications without a doctor's prescription <a href=" http://genericvgrshop.com/# ">buy medication without an rx</a>
    prescription drugs without doctor approval http://genericvgrshop.com viagra without doctor script
    <a href=http://genericvgrshop.com/#>buy medication without an rx</a> buy generic viagra here

  11. KimGal KimGal 发布于 2021年1月23日 07:21 #

    <a href="https://azithromycinzithromax.com/">can i buy azithromycin online</a>

  12. JaneGal JaneGal 发布于 2021年1月23日 07:23 #

    [url=https://viagra10x.com/]sildenafil tablet price[/url]

  13. Gregoryclelt Gregoryclelt 发布于 2021年1月23日 07:39 #

    buy generic viagra <a href=" http://genericvgrshop.com/# ">prescription viagra online without doctor</a>
    online drug store http://genericvgrshop.com meds online without doctor prescription
    <a href=http://genericvgrshop.com/#>meds without a doctor prescription</a> generic viagra for sale

  14. Online Payday Loan Online Payday Loan 发布于 2021年1月23日 07:49 #

    <a href="https://wpaloans.com/">loan online instant</a> <a href="https://loanprs.com/">bad credit cash advance</a>

  15. Josephsaima Josephsaima 发布于 2021年1月23日 07:57 #

    generic viagra <a href=" http://genericvgrshop.com/# ">meds online without doctor prescription</a>
    sexual dysfunction in men http://genericvgrshop.com buy prescription viagra
    <a href=http://genericvgrshop.com/#>prescription viagra without a doctor</a> buy generic viagra

  16. AliceHof AliceHof 发布于 2021年1月23日 08:22 #

    <a href=https://playcasinoonline24.com/>casino money</a>
    <a href="https://playcasinoonline24.com/">casino</a>

  17. NickGal NickGal 发布于 2021年1月23日 09:04 #

    <a href="http://tretinoinretinacream.com/">tretinoin 005</a> <a href="http://amoxicillintrimox.com/">augmentin 500 uk</a> <a href="http://propeciaafinasteride.com/">finpecia 1mg</a> <a href="http://metforminsale.com/">metformin buy online without prescription</a> <a href="http://tadalafilxl.com/">tadalafil otc canada</a> <a href="http://trazodonesari.com/">trazodone sale</a> <a href="http://finasteridepropecia.com/">propecia proscar</a>

  18. JamesTab JamesTab 发布于 2021年1月23日 09:42 #

    viagra only 0.2$ <a href=" http://genericvgrshop.com/# ">viagra</a>
    best male ed pills http://genericvgrshop.com prescription viagra online without doctor
    <a href=http://genericvgrshop.com/#>generic viagra for ed</a> meds without a doctor prescription

  19. WayneLax WayneLax 发布于 2021年1月23日 10:16 #

    buy generic viagra here <a href=" http://genericvgrshop.com/# ">generic viagra for ed</a>
    best ed pills http://genericvgrshop.com generic viagra without a doctor prescription
    <a href=http://genericvgrshop.com/#>generic viagra</a> buy medication without an rx

  20. Josephsaima Josephsaima 发布于 2021年1月23日 11:08 #

    buy cheap prescription viagra online <a href=" http://genericvgrshop.com/# ">buy generic viagra here</a>
    drugs and medications http://genericvgrshop.com buy medication without an rx
    <a href=http://genericvgrshop.com/#>generic viagra</a> medications without a doctor's prescription

  21. JamesTab JamesTab 发布于 2021年1月23日 11:59 #

    generic viagra without a doctor prescription <a href=" http://genericvgrshop.com/# ">buy generic viagra</a>
    male erectile dysfunction http://genericvgrshop.com buy cheap prescription viagra online
    <a href=http://genericvgrshop.com/#>meds online without doctor prescription</a> generic viagra for ed

  22. Gregoryclelt Gregoryclelt 发布于 2021年1月23日 12:03 #

    meds online without doctor prescription <a href=" http://genericvgrshop.com/# ">buy cheap prescription viagra online</a>
    male enhancement pills http://genericvgrshop.com viagra
    <a href=http://genericvgrshop.com/#>buying prescription viagra from canada</a> viagra only 0.2$

  23. KimGal KimGal 发布于 2021年1月23日 12:24 #

    <a href="https://oipharmacy.com/">legitimate online pharmacy</a>

  24. AmyGal AmyGal 发布于 2021年1月23日 12:59 #

    <a href="http://cymbaltadulox.com/">cymbalta generic price usa</a>

  25. EvaGal EvaGal 发布于 2021年1月23日 13:11 #

    <a href="http://cialistore.com/">canadian cialis no prescription</a>

  26. JamesTab JamesTab 发布于 2021年1月23日 14:26 #

    viagra only 0.2$ <a href=" http://genericvgrshop.com/# ">buy generic viagra</a>
    best ed treatment pills http://genericvgrshop.com viagra
    <a href=http://genericvgrshop.com/#>buy viagra very cheap</a> prescription viagra without a doctor

  27. SamGal SamGal 发布于 2021年1月23日 14:45 #

    <a href="http://celexacitaloprampill.com/">citalopram</a> <a href="http://wellbutrinbupropionpill.com/">wellbutrin discount price</a> <a href="http://inderalpropranolol.com/">propranolol drug</a> <a href="http://metforminsale.com/">glucophage 500</a> <a href="http://levitravardena.com/">levitra canada for sale</a> <a href="http://fildenasildenafil.com/">cheap generic viagra canada</a> <a href="http://quetiapineseroquel.com/">buy seroquel online australia</a> <a href="http://chloroquinelab.com/">chloroquine tablets uk</a>

  28. EvaGal EvaGal 发布于 2021年1月23日 14:53 #

    <a href="http://propeciaafinasteride.com/">purchase generic propecia</a>

  29. Gregoryclelt Gregoryclelt 发布于 2021年1月23日 15:06 #

    prescription viagra online without doctor <a href=" http://genericvgrshop.com/# ">prescription viagra without a doctor</a>
    buy prescription drugs from canada cheap http://genericvgrshop.com buy cheap prescription viagra online
    <a href=http://genericvgrshop.com/#>prescription viagra without a doctor</a> meds online without doctor prescription

  30. AllMyknizE AllMyknizE 发布于 2021年1月23日 15:47 #

    <a href=https://ivanovo.remontkompyuterov.su/remont-kompyuterov-ivanovo/>Ремонт компьютеров в Иваново</a>
    <a href=https://all-my-services.com/tyumen/remont-i-obsluzhivanie-tekhniki/kompyuternaya-tekhnika/remont-kompyuterov/>Ремонт компьютеров в Тюмени</a>
    <a href=https://all-my-services.com/tyumen/remont-i-obsluzhivanie-tekhniki/kompyuternaya-tekhnika/kompyuternye-uslugi/>Компьютерная помощь объявления</a>
    <a href=https://all-my-services.com/yoshkar-ola/remont-i-obsluzhivanie-tekhniki/kompyuternaya-tekhnika/remont-kompyuterov/>ремонт компьютера в Йошкар-Оле</a>

  31. BruceFox BruceFox 发布于 2021年1月23日 16:06 #

    viagra without doctor script <a href=" http://genericvgrshop.com/# ">buy prescription viagra online without</a>

  32. JamesTab JamesTab 发布于 2021年1月23日 16:48 #

    meds online without doctor prescription <a href=" http://genericvgrshop.com/# ">buy cheap prescription viagra online</a>
    ed medication http://genericvgrshop.com generic viagra for sale
    <a href=http://genericvgrshop.com/#>buy medication without an rx</a> viagra Without a Doctor Prescription

  33. WayneLax WayneLax 发布于 2021年1月23日 16:57 #

    viagra <a href=" http://genericvgrshop.com/# ">buy generic viagra here</a>
    herbal ed treatment http://genericvgrshop.com buy prescription viagra
    <a href=http://genericvgrshop.com/#>viagra</a> generic viagra without doctor's prescription

  34. JackGal JackGal 发布于 2021年1月23日 17:01 #

    <a href="https://metforminsale.com/">metformin brand name</a> <a href="https://wellbutrinabupropion.com/">zyban online</a> <a href="https://zyloprimallopurinol.com/">allopurinol tablets for sale</a> <a href="https://oipharmacy.com/">canadian family pharmacy</a>

  35. JaneGal JaneGal 发布于 2021年1月23日 17:13 #

    <a href="https://clomidoral.com/">where can i buy clomid medicine</a>

  36. Josephsaima Josephsaima 发布于 2021年1月23日 17:57 #

    generic viagra <a href=" http://genericvgrshop.com/# ">generic viagra without a doctor prescription</a>
    over the counter ed drugs http://genericvgrshop.com buy medication without an rx
    <a href=http://genericvgrshop.com/#>buy prescription viagra online without</a> viagra Without a Doctor Prescription

  37. Gregoryclelt Gregoryclelt 发布于 2021年1月23日 18:09 #

    generic viagra for ed <a href=" http://genericvgrshop.com/# ">viagra</a>
    ed remedies http://genericvgrshop.com prescription viagra without a doctor
    <a href=http://genericvgrshop.com/#>buy cheap prescription viagra online</a> generic viagra without a doctor prescription

  38. KimGal KimGal 发布于 2021年1月23日 18:42 #

    <a href="https://levitrart.com/">levitra pill generic</a>

  39. JamesTab JamesTab 发布于 2021年1月23日 19:17 #

    buy prescription viagra online without <a href=" http://genericvgrshop.com/# ">meds without a doctor prescription</a>
    ed pills that work http://genericvgrshop.com meds without a doctor prescription
    <a href=http://genericvgrshop.com/#>generic viagra for ed</a> buy generic viagra

  40. SueGal SueGal 发布于 2021年1月23日 19:24 #

    <a href="https://tadalafilxl.com/">cialis 10mg price canada</a> <a href="https://lasixfurosemidemed.com/">buy generic lasix</a> <a href="https://avanapill.com/">can i buy dapoxetine over the counter</a> <a href="https://clomidclomifene.com/">purchase clomid online</a> <a href="https://azithromycinzithromax.com/">buy zithromax without prescription online</a> <a href="https://upsildenafil.com/">sildenafil 36</a> <a href="https://cialisdrug.com/">cilais</a> <a href="https://tetracyclineonline.com/">tetracyclinbe</a> <a href="https://finasteridefinpecia.com/">propecia generic canada</a> <a href="https://citamoxifen.com/">tamoxifen 10 mg tablet</a>

  41. JaneGal JaneGal 发布于 2021年1月23日 20:14 #

    <a href="https://levitrart.com/">generic vardenafil canadian pharmacy</a>

  42. Josephsaima Josephsaima 发布于 2021年1月23日 20:22 #

    viagra <a href=" http://genericvgrshop.com/# ">buy prescription viagra online without</a>
    ed pills online pharmacy http://genericvgrshop.com buy viagra very cheap
    <a href=http://genericvgrshop.com/#>buy medication without an rx</a> generic viagra for sale

  43. Gregoryclelt Gregoryclelt 发布于 2021年1月23日 21:26 #

    buy medication without an rx <a href=" http://genericvgrshop.com/# ">generic viagra without doctor's prescription</a>
    male erection pills http://genericvgrshop.com prescription viagra without a doctor
    <a href=http://genericvgrshop.com/#>generic viagra for sale</a> generic viagra without a doctor prescription

发表评论