Slide 1

Slide 1 text

nginxͷύϑΥʔϚϯενϡʔχϯά Tatsuhiko Kubo@cubicdaiya Shibuya.pm#17@2015/06/02

Slide 2

Slide 2 text

@cubicdaiya / Tatsuhiko Kubo w 4PGUXBSF&OHJOFFSJO*OGSBTUSVDUVSF &OHJOFFSJOH!.FSDBSJ *OD w "VUIPSPGOHJOYCVJME w OHJOYSEQBSUZNPEVMFEFWFMPQFS w OHY@TNBMM@MJHIU OHY@EZOBNJD@VQTUSFBN FUDʜ w 'BWPSJUFT(P $ -VB OHJOY OHY@MVB

Slide 3

Slide 3 text

ੲnginxͷಛूهࣄΛॻ͖·ͨ͠

Slide 4

Slide 4 text

mozaic.fm#18ʹήετग़ԋ͠·ͨ͠ IUUQNP[BJDGN

Slide 5

Slide 5 text

Agenda w OHJOYͷجຊతͳνϡʔχϯά w OHJOYͱIPͷϕϯνϚʔΫ w ߲໨ผνϡʔχϯά w H[JQѹॖ w όοϑΝϦϯά w )5514

Slide 6

Slide 6 text

nginx.conf w σϑΥϧτͩͱอकతͳઃఆ͕ଟ͍ w ͋ΒΏΔ؀ڥͰಈ࡞͢ΔΑ͏ʹߟྀ͞ΕͯΔ w σΟϨΫςΟϒͨ͘͞Μ w OHY@DPSF@NPEVMF͚ͩͰݸҎ্

Slide 7

Slide 7 text

core functionality w XPSLFS@QSPDFTTFT w ϫʔΧϓϩηε਺ w XPSLFS@DPOOFDUJPOT w ϫʔΧຖͷ࠷େ઀ଓ਺ w XPSLFS@SMJNJU@OPpMF w ϫʔΧϓϩηε͕PQFOͰ͖ΔGEͷ࠷େ਺

Slide 8

Slide 8 text

σϑΥϧτ஋ XPSLFS@QSPDFTTFT FWFOUT\ XPSLFS@DPOOFDUJPOT ^ XPSLFS@SMJNJU@OPpMFͷσϑΥϧτ஋͸04ґଘ

Slide 9

Slide 9 text

worker_processes w $16ͷίΞ਺Λ໨҆ʹ w BVUPʹ͢Δͱࣗಈతʹ$16ίΞ਺ͷϫʔΧʔϓ ϩηε͕ىಈ͢Δ w ઀ଓ਺ʹԠͯ͡େ͖͘͢Δ w $16ό΢ϯυʹͳΓͦ͏ͳΒ͞Βʹେ͖Ίʹ͢Δ w FHOHY@TNBMM@MJHIU OHY@MVB

Slide 10

Slide 10 text

worker_connections w ௨ৗ͸਺ઍ ʙ Ͱे෼ w ສ୯ҐͰ΋͍͚ͦ͏͚ͩͲ΍ͬͨ͜ͱͳ͍ w XPSLFS@QSPDFTTFTͱηοτͰߟ͑Δ w ϓϩΩγઌͷ઀ଓ਺΋ؚ·ΕΔ఺ʹ஫ҙ

Slide 11

Slide 11 text

worker_rlimit_nofile w ϫʔΧϓϩηε͕ΦʔϓϯͰ͖ΔGEͷ࠷େ਺ w XPSLFS@DPOOFDUJPOTΑΓ΋༏ઌ͞ΕΔͷͰ஫ҙ XPSLFS@SMJNJU@OPpMF

Slide 12

Slide 12 text

νϡʔχϯάܥσΟϨΫςΟϒ(Ұ෦) w TFOEpMF w LFFQBMJWF@UJNFPVU w PQFO@pMF@DBDIF w UDQ@OPEFMBZ w UDQ@OPQVTI w MJTUFO

Slide 13

Slide 13 text

sendfile w TFOpMFγεςϜίʔϧͷ༗ޮԽ w σϑΥϧτͩͱແޮ TFOEpMFPO

Slide 14

Slide 14 text

keepalive_timeout w ΫϥΠΞϯτͱͷΩʔϓΞϥΠϒ઀ଓͷ λΠϜΞ΢τ஋ LFFQBMJWF@UJNFPVUT

Slide 15

Slide 15 text

open_file_cache w Ұ౓։͍ͨϑΝΠϧ৘ใΛΩϟογϡ w ϑΝΠϧͷGEɺαΠζɺߋ৽೔࣌ PQFO@pMF@DBDIFNBYJOBDUJWFT

Slide 16

Slide 16 text

tcp_nodelay w 5$1@/0%&-":Φϓγϣϯͷ༗ޮԽ w σϑΥϧτͰ༗ޮ w /BHMFΞϧΰϦζϜΛېࢭ UDQ@OPEFMBZPO

Slide 17

Slide 17 text

tcp_nopush w 5$1@/0164)Φϓγϣϯͷ༗ޮԽ w -JOVYͩͱ5$1@$03,Φϓγϣϯ w TFOEpMF༗ޮ࣌ͷΈར༻Մೳ UDQ@OPQVTIPO

Slide 18

Slide 18 text

TCP_NODELAYͱTCP_NOPUSH w ͜ͷೋͭ͸ຊདྷ૬൓͢Δಈ࡞Λ͢Δ w 5$1@/0%&-": w ύέοτΛͰ͖Δ͚ͩଈ࠲ʹૹ৴͢Δ w 5$1@/0164) w ύέοτΛͰ͖Δ͚ͩ·ͱΊͯૹ৴͢Δ w OHJOY͸྆ํ૊Έ߹ΘͤՄೳ ཁTFOEpMF w ·ͣɺύέοτૹ৴Λ5$1@/0164)Ͱ஗Ԇͤ͞Δ 5$1@/0164)ΛPGG5$1@/0%&-":Ͱϑϥογϡ

Slide 19

Slide 19 text

listen ύϥϝʔλଟ͗͢

Slide 20

Slide 20 text

ύϑΥʔϚϯεʹӨڹ͢Δ ओͳlistenύϥϝʔλ w TQEZ41%:Λ༗ޮʹ͢Δ w CBDLMPH/MJTUFOͷόοΫϩά਺ w OFUDPSFTPNBYDPOO౳΋๨Εͣʹ w GBTUPQFO/5$1'BTU0QFO w SFVTFQPSU40@3&64&1035Λ༗ޮʹ͢Δ

Slide 21

Slide 21 text

nginxͱh2oͷϕϯνϚʔΫ w DYMBSHFPO&$ w IPBMQIB w OHJOY w XSLͰϕϯνϚʔΫ w XSLDUEIUUQ

Slide 22

Slide 22 text

h2o.conf(࠷దԽલ) MJTUFO IPTUT QBUIT pMFEJSVTSMPDBMOHJOYIUNM

Slide 23

Slide 23 text

h2o.conf(࠷దԽޙ) OVNUISFBET OVNOBNFSFTPMVUJPOUISFBET NBYDPOOFDUJPOT MJTUFO IPTUT QBUIT pMFEJSVTSMPDBMOHJOYIUNM

Slide 24

Slide 24 text

nginx.conf(࠷దԽલ) XPSLFS@QSPDFTTFT FWFOUT\ XPSLFS@DPOOFDUJPOT ^ IUUQ\ JODMVEFNJNFUZQFT EFGBVMU@UZQFBQQMJDBUJPOPDUFUTUSFBN BDDFTT@MPHPGG TFOEpMFPO LFFQBMJWF@UJNFPVU TFSWFS\ MJTUFO TFSWFS@OBNFMPDBMIPTU MPDBUJPO\ SPPUIUNM JOEFYJOEFYIUNMJOEFYIUN ^ ^ ^

Slide 25

Slide 25 text

nginx.conf(࠷దԽޙ) XPSLFS@QSPDFTTFT FWFOUT\ XPSLFS@DPOOFDUJPOT BDDFQU@NVUFY@EFMBZNT ^ IUUQ\ JODMVEFNJNFUZQFT EFGBVMU@UZQFBQQMJDBUJPOPDUFUTUSFBN BDDFTT@MPHPGG TFOEpMFPO PQFO@pMF@DBDIFNBYJOBDUJWFT UDQ@OPQVTIPO LFFQBMJWF@UJNFPVU TFSWFS\ MJTUFO TFSWFS@OBNFMPDBMIPTU MPDBUJPO\ SPPUIUNM JOEFYJOEFYIUNMJOEFYIUN ^ ^ ^

Slide 26

Slide 26 text

nginxͱh2oͷϕϯνϚʔΫ SFRT SFRTFD XSLDUEIUUQ

Slide 27

Slide 27 text

nginxͱgzipѹॖ w H[JQH[JQѹॖΛ༗ޮʹ͢Δ w H[JQ@UZQFTH[JQѹॖର৅ͷ$POUFOU5ZQF w H[JQ@DPNQ@MFWFMH[JQͷѹॖϨϕϧ w H[JQ@TUBUJDH[JQѹॖࡁΈϑΝΠϧͷ഑৴ w HVO[JQH[JQղౚ

Slide 28

Slide 28 text

gzipѹॖͷઃఆྫ H[JQPO H[JQ@DPNQ@MFWFM H[JQ@UZQFTUFYUDTT UFYUKBWBTDSJQU BQQMJDBUJPOKBWBTDSJQU BQQMJDBUJPOKTPO

Slide 29

Slide 29 text

nginxͱgzipѹॖ w ੩తίϯςϯπͷH[JQѹॖ͸ੵۃతʹ͢΂͖ w $16ͷΦʔόʔϔουΑΓ΋ωοτϫʔΫͷ ϨΠςϯγͷํ͕͸Δ͔ʹେ͖͍ w $16Ϧιʔεͷফඅྔ͕ແࢹͰ͖ͳ͍৔߹ w H[JQ@TUBUJDͰH[JQѹॖࡁΈϑΝΠϧΛ഑৴

Slide 30

Slide 30 text

gzip_staticͷઃఆྫ YYY DTTcKT H[͕ଘࡏͨ͠ΒͦΕΛͦͷ··഑৴ ΫϥΠΞϯτ͕H[JQѹॖΛαϙʔτ͍ͯ͠ͳ͍৔߹͸H[ϑΝΠϧΛల։ͯ͠഑৴ MPDBUJPOd= DTTcKT \ H[JQ@TUBUJDBMXBZT HVO[JQPO ^

Slide 31

Slide 31 text

zopfliͰ͞Βʹѹॖ w EFqBUFޓ׵ͷѹॖΞϧΰϦζϜπʔϧ w IUUQTHJUIVCDPNHPPHMF[PQqJ w [PQqJͰѹॖͨ͠΋ͷ͸HVO[JQՄೳ w ѹॖ཰͕ߴ͍෼ɺѹॖʹ͔͔Δ͕࣌ؒ௕͍ w ࣄલʹѹॖ͢ΔͷͰ໰୊ʹͳΒͳ͍

Slide 32

Slide 32 text

nginxͱόοϑΝϦϯά w DMJFOU@CPEZ@CVGGFS@TJ[F w QSPYZ@CVGGFS@TJ[F w QSPYZ@CVGGFST w QSPYZ@CVGGFSJOH w QSPYZ@SFRVFTU@CVGGFSJOH w FUDʜ

Slide 33

Slide 33 text

όοϑΝϦϯάͷOn/Off w QSPYZ@CVGGFSJOH EFGBVMUPO w FHετϦʔϛϯά૬౰ͷॲཧΛ͢Δࡍʹ PGGʹ͢Δ͔ݕ౼ w QSPYZ@SFRVFTU@CVGGFSJOH EFGBVMUPO w FHେ͖ͳϑΝΠϧͷΞοϓϩʔυ͕ൃੜ͢Δࡍ ʹPGGʹ͢Δ͔ݕ౼ ಛʹཧ༝͕ͳ͍ݶΓσϑΥϧτͰ0,

Slide 34

Slide 34 text

όοϑΝϦϯάͱI/O w OHJOYͷ֤όοϑΝͷαΠζ͸ൺֱతখ͞Ί w େମ਺,#ఔ౓ w όοϑΝ͕଍Γͳ͘ͳΔͱσΟεΫʹॻ͖ग़͢ w όοϑΝαΠζΛௐ੔PSUNQGTΛར༻

Slide 35

Slide 35 text

όοϑΝϦϯάͱtmpfs ϦΫΤετϘσΟͷॻ͖ग़͠ઌ DMJFOU@CPEZ@UFNQ@QBUIEFWTINDCU ϓϩΩγઌϨεϙϯεϘσΟͷॻ͖ग़͠ઌ QSPYZ@UFNQ@QBUIEFWTINQU ɾ ɾ ɾ

Slide 36

Slide 36 text

HTTPSؔ࿈ͷνϡʔχϯά w 5-44FTTJPO$BDIF w 5-44FTTJPO5JDLFUT w 0$414UBQMJOH w 41%: w 0QUJNJ[JOHUIF5-4SFDPSETJ[F

Slide 37

Slide 37 text

TLS Session Cache w 5-4ϋϯυγΣΠΫͷηογϣϯΛαʔόʹ Ωϟογϡ w OHJOYͰ͸ڞ༗ϝϞϦ্ͷอଘ͞ΕΔ w ࣍ճͷ5-4ϋϯυγΣΠΫΛলུ

Slide 38

Slide 38 text

TLS Session Cache with nginx TTM@TFTTJPO@DBDIFTIBSFE44-N TTM@TFTTJPO@UJNFPVUN

Slide 39

Slide 39 text

TLS Session Tickets w ҉߸Խͨ͠ηογϣϯ νέοτ ΛΫϥΠΞϯτ ʹ౉͢ w νέοτΛݩʹ5-4ηογϣϯΛ࠶։ w )5514αʔόෳ਺୆ͰηογϣϯΛڞ༗

Slide 40

Slide 40 text

TLS Session Tickets with nginx TTM@TFTTJPO@UJDLFUTPO TTM@TFTTJPO@UJDLFU@LFZFUDOHJOYTTMUJDLFULFZ

Slide 41

Slide 41 text

OCSP Stapling w 0$41ʹΑΔ44-ূ໌ॻͷࣦޮ֬ೝΛαʔόଆ ͰߦͬͯΩϟογϡ w ΫϥΠΞϯτଆͰ΍Δͱ5-4ϋϯυγΣΠΫ࣌ ʹϨΠςϯγൃੜ

Slide 42

Slide 42 text

OCSP Stapling with nginx TTM@TUBQMJOHPO TTM@TUBQMJOH@WFSJGZPO TTM@USVTUFE@DFSUJpDBUFFUDOHJOYTTMDFSUDSU SFTPMWFSYYYYYYYYYYYYWBMJET SFTPMWFS@UJNFPVUT

Slide 43

Slide 43 text

SPDY with nginx MJTUFOTTMTQEZ

Slide 44

Slide 44 text

Optimizing the TLS-record size w 5-4Ͱ͸ҰఆαΠζຖʹ௨৴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SLJOH w 0`3FJMMZ *MZB(SJHPSJL

Slide 48

Slide 48 text

w OHJOYͷύϥϝʔλνϡʔχϯάͱIP w IUUQRJJUBDPNDVCJDEBJZBJUFNTEDFDCF w OHJOYύϑΥʔϚϯενϡʔχϯάʙ੩తίϯςϯπ഑৴ฤʙ w IUUQRJJUBDPNDVCJDEBJZBJUFNTCBBCEEE w OHJOYͷϦΫΤετϘσΟͷόοϑΝϦϯάʹؔ͢Δ໰୊ͱͦͷվળࡦ w IUUQRJJUBDPNDVCJDEBJZBJUFNTGFFE ࢀߟจݙ / URL

Slide 49

Slide 49 text

࠷ޙʹએ఻

Slide 50

Slide 50 text

YAPC::Asia Tokyo2015 ͷτʔΫʹԠื͠·ͨ͠ IUUQZBQDBTJBPSHUBMLTIPXBGGFBGCCEDB ࣮ફOHJOYϞδϡʔϧ։ൃʙ$ͱ-VBʙ