Upgrade to Pro — share decks privately, control downloads, hide ads and more …

FUJIMIのFastly活用事例集

Kono Junya
March 29, 2022

 FUJIMIのFastly活用事例集

Fastly User Meetup #4 の登壇資料です

https://fastly-community.connpass.com/event/241481

Kono Junya

March 29, 2022
Tweet

More Decks by Kono Junya

Other Decks in Technology

Transcript

  1. 'BTUMZʷ'6+*.* if(req.url.path ~ “^/xxx”) { set req.backend = Origin2; }

    YYY ʹର͢ΔϦΫΤετʹରͯ͠$MPVE3VOΛPSJHJOͱ͢Δ
  2. 'BTUMZʷ'6+*.* *NBHF0QUJNJ[FS if(req.url.ext ~ “(?i)^(gif|png|jpe?g)$”) { if(req.http.Save-Data) { set req.url

    = req.url.path “?quality=440”; } } 'BTUMZ*NBHF0QUJNJ[FSΛ࢖͏ར఺  ($1ͳͲʹରͯ͠BTTFUTΛEFQMPZͤͣʹ͢Ή  ্هͷΑ͏ʹIUUQGJFMEͰ෼ذΛ͢Δ͜ͱ͕Ͱ͖Δ  4VSSPHBUF,FZʹΑΔDBDIFͷΠϯελϯτύʔδ͕ߦ͑Δ
  3. $PNQVUF!&EHFʷ'6+*.* -1ͷϦμΠϨΫτXJUI$!& GET /pt101 HTTP/2 Host: pr.fujimi.me HTTP/2 308 Location:

    https://fujimi.me/lp/protein 3FRVFTU 3FTQPOTF let path = req.get_path(); let path = match path { path if path.contains(“pt”) => “/protein”, _ => path, }; Ok(Response::from_status(StatusCode::PERMANENT_REDIRECT).with_header( header::LOCATION, format!(“https://fujimi.me/lp{}”, path), )) src/main.rs
  4. $PNQVUF!&EHFʷ'6+*.* 1SFWJFX؀ڥ a֬ೝ͠·͢ʂʂ aͰ͖ͨʂ 1. %FW 1VMM3FRVFTUΛϚʔδ 1.͕֬ೝ͢ΔͨΊʹ 13ΛNBJOCSBODIʹϚʔδ͠ͳ͍ͱ͍͚ͳ͍ʜ ໰୊఺

     1.͕ϨϏϡʔͯ͠μϝͩͬͨ৔߹ɺSFWFSUPSमਖ਼13Λ͋͛ͳ͍ͱ͍͚ͳ͍  ະ׬੒ͳ΋ͷΛNBJOCSBODI΁Ϛʔδ͠ͳ͚Ε͹ͳΒͳ͍
  5. $BTF4UVEZʹܝࡌ͞Ε·ͨ͠🎉 ࠓ೔ͷ͓࿩ͷҰ෦ΛΑΓৄ͓͘͠࿩͍ͯ͠ΔͷΛ $BTF4UVEZʹܝࡌ͍͍ͯͨͩͨ͠ͷͰੋඇΈ͍ͯͩ͘͞ʂ ˜'BTUMZ *OD"MM3JHIUT3FTFSWFE 'BTUMZ ͷ $%/ͱ$PNQVUF!&EHFͰ '6+*.*ެࣜαΠτΛڧԽ ςϨϏ$.Ͱ໿ഒʹ૿͑ͨΞΫηεʹ

    ઃఆมߋͳ͠ͰରԠ ඒ༰෼ੳ͔Βͭ͘Δ͋ͳͨͷͨΊͷύʔιφϥΠζϏϡʔςΟϒϥϯυͰ͋Δ'6+*.*Λ த৺ʹࣄۀΛల։͢ΔτϦίגࣜձࣾïҎԼɺτϦίðɻެࣜαΠτͰ͋ΔGVKJNJNFʹɺ 'BTUMZͷ$%/ɺΠϝʔδΦϓςΟϚΠβʔɺ͓Αͼ$PNQVUF!&EHFΛ࠾༻ɻ Ωϟογϡͷώοτ཰ˋҎ্ɺΩϟογϡΧόϨοδˋΛ࣮ݱ͢Δͱͱ΋ʹɺ ςϨϏ $.ͷެ։ʹΑΔഒҎ্ͷΞΫηεͷ֦େʹ΋αʔόʔ؀ڥͷઃఆΛมߋ͢Δ͜ͱͳ͘ ରԠͰ͖Δ࢓૊ΈΛ࣮ݱͨ͠ɻ 'BTUMZ τϦίגࣜձࣾ $"4&456%: ໊ࣾāτϦίגࣜձࣾ ॅॴā˟ ɹɹɹ ౦ژ౎৽॓۠৽॓େڮޚԓϏϧ' 63-ɿIUUQTUSJDPUJODDPN ೥݄ʹઃཱɻඒ༰෼ੳʹΑΓύʔιφϥΠζ͞Εͨα ϓϦϝϯτɺϓϩςΠϯɺϑΣΠεϚεΫΛఏڙ͢ΔϏϡʔ ςΟϒϥϯυʮ'6+*.*ʯͷࣄۀΛల։ɻ ೥݄ʹ͸ɺ ϧϛω৽॓ళʹॳͷৗઃళΛΦʔϓϯͨ͠ɻ ໊ࣾʹ͸ɺ͓٬༷ʹѪ͞ΕΔϓϩμΫτΛ૑Γɺເதʹͳͬ ͯ΄͍͠ͱ͍͏ʮྂʯͱɺ͓٬༷ͷ੠ΛͭͻͱͭஸೡʹฤΈ ্͛ɺਓʹدΓఴͬͨϓϩμΫτΛ૑Δͱ͍͏ϑϥϯεޠͷ ʮUSJDPUʢฤΈ෺ʣʯ ͷͭͷ૝͍͕ࠐΊΒΕ͍ͯΔɻ w $%/ ಋೖͱ 3JPUKT ͔Β /FYUKT ΁ͷҠߦͷ ͭΛ໨తʹ 'BTUMZ Λ࠾༻ ɹʮࢲΒ͍͠ඒ͠͞ͰɺࢲΛ΋ͬͱ޷͖ʹͳΔ⼧ͱ͍͏ϛογϣϯʹج͖ͮӡӦ͢Δ '6+*.* GVKJNJNF ͸Ŋ໿ʙ໰ͷඒ༰ʹؔ͢Δઃ໰ʹ౴͑Δ͜ͱͰɺͦͷ෼ੳ ݁Ռ͔ΒύʔιφϥΠζ͞ΕͨΦϦδφϧͷαϓϦϝϯτ΍ϑΣΠεϚεΫɺϓ ϩςΠϯΛߪೖͰ͖ΔެࣜαΠτͰ͋Δɻओʹʙ୅ͷঁੑʹࢧ࣋͞ΕɺΞΫ ςΟϒϢʔβʔ਺͸ສϢʔβʔҎ্ɻ௚ۙΧ݄ͷϖʔδϏϡʔï 17 ðͷฏۉ ͸ɺສ17Λ௒͍͑ͯΔɻ ɹ౰ॳɺGVKJNFNF Ͱ͸ίϯςϯπ഑৴ωοτϫʔΫ $%/ ͕ಋೖ͞Ε͍ͯͳ͔ͬ ͨɻ͔͠͠ɺ೥݄ʹλϨϯτΛى༻ͨ͠ςϨϏ$. ͷެ։͕ܾ·ͬͨ͜ͱ͔ Βɺ$%/ͳ͠ͷ··ςϨϏ$.Λެ։͢Δ͜ͱ͸ɺαʔόʔͷෛՙ૿େʹΑΔγες ϜఀࢭͷϦεΫ͕ߴ͔ͬͨɻ·ͨɺςϨϏ$.ͷެ։௚લͷ೥݄ʹ৽੡඼Ͱ͋ ΔϓϩςΠϯΛϦϦʔε͍͕ͯͨ͠ɺٕज़తͳ໰୊͔Β$%/ͷಋೖ͕ඞཁͩͬͨɻ ɹ-FBE 8FC &OHJOFFS ͷՏ໺७໵ࢯ͸ɺ⼦αϓϦϝϯτͱϑΣΠεϚεΫͷΞϓϦ έʔγϣϯ͸ɺ3JPUKT ͱ͍͏গ͠ݹ͍ +BWB4DSJQU ͷϑϨʔϜϫʔΫͰ࣮૷͞Ε ͍ͯͨͷͰ͕͢ɺ ॊೈͳઃܭʹͳ͍ͬͯͳ͍ͨΊɺͦ͜ʹϓϩςΠϯͷ৽نϓϥο τϑΥʔϜΛ௥Ճ͢Δͷ͸։ൃମݧ͕Α͘ͳ͍ͱߟ͑·ͨ͠ɻͦ͜Ͱ /FYUKT ͱ 5ZQF4DSJQUʹΑΔΞϓϦέʔγϣϯ։ൃʹҠߦ͍ͨ͠ͱࢥ͍ͬͯ·ͨ͠ʯͱ࿩͢ɻ ɹαϓϦϝϯτͱϑΣΠεϚεΫͷΞϓϦέʔγϣϯΛ 3JPUKT ͔Β /FYUKTʹҰ ؾʹॻ͖׵͑Δͱ։ൃͱ2" ඼࣭อূ ʹ޻਺͕͔͔ͬͯ͠·͏ɻ ͦ͜Ͱɺผͷαʔ όʔͰϓϩςΠϯͷΞϓϦέʔγϣϯΛ։ൃ͠ͳ͕ΒɺGVKJNJNF͔ΒΞΫηεͰ ͖ΔΑ͏ʹ͢Δ͜ͱ͕ඞཁͩͬͨɻՏ໺ࢯ͸ɺ ⼦'BTUMZ Ͱ͋Ε͹ɺ7$- 7BSOJTI $POpHVSBUJPO -BOHVBHF Λ࢖͏͜ͱͰɺ ͜ΕΛ࣮ݱͰ͖Δͱߟ͑·ͨ͠ʯ ͱ࿩͢ɻ ɹݕ౼ͷ݁Ռɺ೥݄ʹ 'BTUMZ ͷ࠾༻Λܾఆɻ࠾༻ͷཧ༝ΛՏ໺ࢯ͸ɺʮલ ৬Ͱ 'BTUMZ Λ࢖ͬͨ͜ͱ͕͋ΔͷͰ͕͢ɺ'BTUMZ ͷڧΈͰ͋Δ 7$- Λར༻ͨ͠ ॊೈͳઃܭ͕Մೳͳ͜ͱΛධՁ͠·ͨ͠ɻ·ͨɺ৽͍͠ΞϓϦέʔγϣϯΛϦϦʔε ͨ͠ͱ͖ʹɺΩϟογϡΛύʔδ͠ͳ͚Ε͹ͳΒͳ͍ͷͰ͕͢ɺ'BTUMZ Ͱ͋Ε͹Π ϯελϯτύʔδͰߴ଎ʹΩϟογϡΛύʔδͰ͖Δ͜ͱ΋࠾༻ΛܾΊͨཧ༝ͷͭ Ͱͨ͠ʯͱ࿩͍ͯ͠Δɻ