课件教程nginx中文_第1页
课件教程nginx中文_第2页
课件教程nginx中文_第3页
课件教程nginx中文_第4页
课件教程nginx中文_第5页
已阅读5页,还剩205页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

nginxphp-fpm安装配置

456

介 模块化的结构。过滤器包括gzip,byteranges,chunkedresponses,以及SSI-filter。 或者FastCGI的多个子请求并发处理;SSLTLSSNIIMAP/POP3服务功能HTTPIMAP/POP3HTTPSMTP后端;POP3:POP3USER/PASS,APOP,AUTHLOGIN IMAP:IMAPLOGIN;SMTP:AUTH INCRAM-IMAPPOP3STARTTLSSTLS支持;BSD3.x,4.x,5.x,6.xi386;BSD5.x,6.xLinux2.2,2.4,2.6i386;Linux2.6Solaris8i386;Solaris9i386andsun4u;Solaris10i386;MacOSX(10.4)PPC;kqueue(BSD4.1+),epoll(Linux2.6+),rtsignals(Linux2.2.19+),/dev/poll(Solaris711/99+),select,以及poll支持;kqueue支持的不同功能包括EV_CLEAR,EV_DISABLE(临时sendfile(BSD3.1+),sendfile(Linux2.2+),sendfile64(Linux2.4.21+),和sendfilev(Solaris87/01+)支持;输入过滤(BSD4.1+)以及TCP_DEFER_ACCEPT(Linux2.4+)支持10,000HTTPkeep-alive2.5M内存。Memcached的GET接口; PCRE的rewrite基于客户端IP地址和HTTP基本认证的控制PUTDELETE,MKCOL通过aio_read(

的套接字工作的实验模块,仅在BSD下 BSD4.x的实现基于Nginx主要的英语站点是AleksandarLazic为什么选择Nginx是一个高性能的Web和反向服务器,它具有有很多非常优越的特性作为Web服务器:相比Apache,Nginx使用更少的资源,支持的并发连接,体现更高Nginx50,000个并发连接数的响应,感谢Nginx为我们选择了epollandkqueue作为开发模型.作为负载均衡服务器:NginxRailsPHPHTTP代理服务器对行服务。Nginx用C编写,不论是系统资源开销还是CPU使用效率都比Perlbal要好的多。作为邮件服务器:Nginx同时也是一个非常优秀的邮件服务器(最早开发这个产品的目的之一也是作为邮件服务器),Last.fm描述了成功并且美妙的使用经验。Nginx启动特别容易,并且几乎可以做到7*24不间断运行,即使运行数个月也不需要重新启动。你还能够在不间断服务的情况下进行软件版本的升级。 ++apt-getapt-getinstallbuild-essentialapt-getinstalllibtoolyum-yinstallyum-yinstallgccautomakeautoconflibtool安装yumyuminstallgccgcc-, cdcdftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/的PCRE源码包,使用下面命令编译和安装PCRE包:cdcdwgetftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.gztar-zxvfpcre-8.34.tar.gzcdpcre-maketar-zxvfzlib-1.2.8.tar.gzcdzlib-1.2.8maketar-zxvfopenssl-安装中一个,下面是把Nginx安装到/usr/local/nginx tar-zxvfnginx-1.4.2.tar.gzcdnginx-1.4.2./configure--sbin-path=/usr/local/nginx/nginx--with-http_ssl_modulemake安装成功后/usr/local/nginx fastcgi_params.defaultmime.types.default 80端口没被其他程序占用,运行/usr/local/nginx/nginx命令来启动netstatnetstat-ano|grepsudosudo打开浏览器此机器的IP,如果浏览器出现 etonginx!则表示Nginx已经安装并libtool:compile:unrecognizedoption`-DHAVE_CONFIG_H'libtool:libtool:compile:unrecognizedoption`-DHAVE_CONFIG_H'libtool:compile:Try`libtool--help'formoreinformation.make[1]:***[pcrecpp.lo]Error1make[1]:Leavingdirectory`/usr/local/src/pcre-8.34'make:***[all]Error2apt-getapt-getinstallapt-getinstallbuild-essentialmakecleanmake:***Noruletomaketarget`build',neededby`default'../configure:error:SSLmodulesrequiretheOpenSSLYoucaneitherdonotenablethemodules,orinstalltheOpenSSLlibraryintothesystem,orbuildtheOpenSSLlibrarystaticallyfromthesourcewithnginxbyusing--with-openssl=apt-getinstallopensslapt-getapt-getinstallopensslapt-getinstalllibssl-devyumyum-yinstallopensslopenssl-

,存放服务器上的文件,也就是nginx的安 。默认用/usr/local/nginx--sbin-path=path设置nginx的可执行文件的路径,默认 --conf-path=path设置在nginx.conf配置文件的路径。nginx允许使用不同的配置文件启 时改变的文件名,在nginx.conf配置文件中使用PID指令。默认情况下,文件名 改变的文件名,在nginx.conf配置文件中使用的error_log指令。默认情况下,文件名 随时改变的文件名,在nginx.conf配置文件中使用的access_log指令。默认情况下,文件名为 —

path—设置PCRE库的源码路径。PCRE库的源码(版本4.4-8.30) 并解压。其余的工作是Nginx的./configure和make来完成。正则表达式使用在location指令和ngx_http_rewrite_module模块中。中,令)

path—设置的zlib库的源码路径。要从zlib(版本1.1.3-1.2.5)的使用zlib。

select()支持的文件数量:--with-cc-opt="-D

--with-ld-opt="-L--with-ld-opt="-L<为-t不运行,而仅仅测试配置文件。nginx将检查配置文件的语法的正确性,并尝试打开配置文-vnginx-Vnginx可以使用信号系统来控制主进程。默认,nginxpid/usr/local/nginx/nginx.pid./configurepid指令,来改变该文TERM,TERM,nginx(ps-ef|grepps-ef|grepkillTERMnginxkill9nginxcatkill信号类型catkillkill-QUIT`catkill-sudo##<strong>psaux|egrep PID%CPU 22130.0 67842036?STATTIME0:00nginx:masterprocess#<strong>kill-15#<strong>#<strong>nginx-t-c2006/09/1613:07:10[info]15686#0:theconfigurationfile/etc/nginx/nginx.confsyntaxi2006/09/1613:07:10[info]15686#0:theconfigurationfile/etc/nginx/nginx.confwastest#<strong>psaux|egrep'(PID|nginx)'</strong> PID%CPU 22130.0 67842036?STATTIME0:00nginx:masterprocess<strong>#kill-HUPnginxHUP信号,它会尝试先解析配置文件(如果指定配置文件,就使用指定的,否则使用默认的),成功的话,就应用新的配置文件(例如:重新打开日志文件或的套接字)。之后,nginx运行新的工作进程并从容关闭旧的工作进程。通知工作进程关闭闭。如果新的配置文件应用失败,nginx将继续使用旧的配置进行工作。nginx首先,使用新的可执行程序替换旧的(最好做好备份),USR2(killUSR2.pid.oldbin(PPID1nginx:master33126nginx:worker33126nginx:worker33126nginx:worker33126nginx:master36264nginx:worker36264nginx:worker36264nginx:workernginx实例会同时运行,一起处理输入的请求。要逐步停止旧的实例,你必须发送WINCH信号给旧的主进程,然后,它的工作进程就将开始从容关闭:PPIDVSZ11164nginx:master331261380nginx:workerisshuttingdown331261148nginx:master362641364nginx:worker362641364nginx:worker362641364nginx:workerPIDPIDPPID 13626433126362653626436266362643626736264VSZ11641148nginx:masterprocess/usr/local/nginx/sbin/nginxnginx:masterprocess1364kqreadnginx:workerprocess(nginx)1364kqreadnginx:workerprocess(nginx)1364kqreadnginx:workerprocessHUP它将在不重载配置文件的情况下启动它的工作进程发送QUIT信号给新的主进程,要求其从容关闭其工作进程发送.oldbin.pid文件,这样,一切PIDPPID VSZWCHAN 1362653626436266362643626736264

0.01148pausenginx:masterprocess0.01364kqreadnginx:workerprocess0.01364kqreadnginx:workerprocess0.01364kqreadnginx:workerprocess例如"8k"1m代表字节数计量.s秒mhd日w周M一个月30y年365例如"1h30m""1y6M""130分1年零6个月 优化考虑到保存键及其值的hash表单元的大小不至于超出设定参数(hashbucketsize),在启直到hash表超过参数(hashmaxsize)的大小才重新进行选择.对于大多数hash表都有指令来 所控制的。参数hashbucketsize总是等于hash表的大小,并hash表键值成为可能。如果hashbucketsize等于一路处理器缓存的大小,那么在查找键的时单元中查找键值。因此,如果Nginx给出需要增大hashmaxsize或hashbucketsize的提

和--without-

kqueue-高效的方法,使用 BSD4.1+,OpenBSD2.9+,NetBSD2.0和, 小。可是从Linux内核版本2.6.6-mm2开始,这个参数就不再使用了,并且对于每个进程 /dev/poll高效的方法,使用于Solaris711/99+HP/UX11.22eventport6.5.15Tru64UNIXeventport-高效的方法,使用于Solaris10.为了防止出现内核的问题,有必要安装这个安全补丁。常见问题[#notwork某些东东不工作(URL重写,,路径,...)][#other有没有其它类似的Web服务器][#chroot对于chroot的支持是否在计划之中?]测试IMAP模块,而不只是关于IMAP的只言片语啊?] 某些东东不工作(URL重写,,路径,请仔细阅读[NginxDebugging]并且逐行查看错误日志。?大体上来说nginx主要用于反向加速而不是像squid那样做为常规服务器。Nginx的最大优势在于高负载情况下内存和CPU的低消耗。我不认为squid能给你带来比nginx更好的性Nginx使用什么算法来实现负载均衡它能实现基于连接数的负>我能关闭从服务器到后端服务器的缓存吗或者使用上传进(2007-Apr-26)还没有办法关闭到后端服务器的缓存调试Nginx的一个级特性就是你能使用debug_connection指令只调试某些连接。这个设置只有是你使用--with-debug编译的nginx才有效。调试 Nginx的基本功能的指令[#daemondaemon][#error_logerror_log][#includeinclude][#lock_filelock_file][#pidpid][#ssl_enginessl_engine][#userusergroup][#worker_cpu_affinityworker_cpu_affinity][#worker_priorityworker_priority][#worker_processesworker_processes][#worker_rlimit_coreworker_rlimit_core][#worker_rlimit_nofileworker_rlimit_nofile][#working_directoryworking_directory]语法:*daemonon|缺省值daemondaemonDonotusethe"daemon"and"master_process"directivesinaproductionmode,daemonoptionsaremainlyusedfordevelopmentonly.Youcandaemonmaster_processmodewithrunit/daemontoolshoweveryoucan'tdoagracefulmaster_process

safelyin语法:*debug_pointsstop|缺省值debug_pointsdebug_pointsTherearesomeassertionpointsinsidenginxthatallowtostopnginxtoattachthedebugger,ortoabortandtocreatethecorefile.语法:*error_logfiledebug|info|notice|warn|error|crit缺省值Nginx添 ,你还能够使用以下配置error_logerror_logLOGFILE[debug_core|debug_alloc|debug_mutex|]:|debug_http|debug_imap语法:*includefile|缺省值 includeinclude语法:*lock_file缺省值:*compile-timelock_filelock_filenginxusesacceptmutextoserializeaccept()syscalls.Ifnginxisbuiltbygcc,InC++,orSunProC++compilersoni386,amd64,sparc64,andppc64,thennginxusestheatomicinstructionstoimplementthemutex.Inothercasesthelockfilewouldbeused.语法:*master_processon|缺省值master_processmaster_processDonotusethe"daemon"and"master_process"directivesinaproductionmode,theseoptionsaremainlyusedfordevelopmentonly.语法:*pid缺省值:*compile-timeoption*pidpidcat进程id文件。可以使用kill-cat语法:*ssl_engine缺省值:*system

Hereyoucansetyourpreferredopensslengineifanyavailable.Youcanfigureoutwhichonedoyouhavewiththecommandlinetool:opensslopensslengine-例如$$opensslengine-(cryptodev)BSDcryptodev:[available(dynamic)Dynamicengineloading:[unavailabletimer_resolutiontimer_resolutionThedirectiveallowstodecreasenumbergettimeofday()syscalls.Bydefaultgettimeofday()iscalledaftereachreturnfromkevent(),epoll,/dev/poll,select(),poll().Butifyouneedanexacttimeinlogswhenlogging$upstream_response_time,or$msecvariables,thenyoushoulduse 语法:*useruser缺省值:*nobodyuserwwwuserwww[Linuxonly.WiththisoptionyoucanbindtheworkerprocesstoaCPU,itcallsForexample,worker_cpu_affinity000100100100BindeachworkerprocesstooneCPUworker_cpu_affinity0101BindthefirstworkertoCPU0/CPU2,bindthesecondworkertoCPU1/CPU3.ThisissuitableforHTT.缺省值Withthisoptionyoucangivetoallworkerprocessesthepriority(nice)youneed/wish,itcallsworker_processesworker_processesnginxhastheabilitytousemorethanoneworkerprocessforseveralreasons:tousetodecreaselatencywhenworkersblockendondisktolimitnumberofconnectionsperprocesswhenselect()/poll()isss

fromtheeventsectionsallowsyoumax_s=worker_processes*缺省值umsizeofcorefileper语法worker_rlimit_nofilelimit缺省值Specifiesthevalueforumfiledescriptorsthatcanbeopenedbythis:(SinceLinux2.6.8)SpecifiesthelimitonthenumberofsignalsthatmaybequeuedfortherealuserIDofthecallingprocess.语法working_directorypath缺省值--Thisistheworkingdirectoryfortheworkers.It'susedforcorefilesonly.nginxusesabsolutepathsonly,allrelativepathsinconfigurationfilesarerelativetoSyntax:*accept_mutex[on|offSyntax:*debug_connection[ip|Since0.3.54thisoptionsupportCIDRaddressThisoptiongivesyoutheabilitytowritedebuglogonlyforthesofthisIP/NET.Severaldifferentdirectivesarepossible.error_logerror_log/var/log/nginx/errors;events{ }Thesedirectivesspecifyhowmanyeventsmaybepassedto/fromkernel,usingappropriateThe valuesare32,therestareSyntax:*multi_accept[on|offtriestoaccept()asmanyconnectionsaspossibleafternginxgetsnotificationaboutanewconnection.nginxusestwosignalswhenthesignalnumber.Thesecondisplus1.

methodisused.ThedirectivespecifiedtheBy isSIGRTMIN+10Thesedirectivesspecifieshowtohandlertsigqueueoverflows.Whenoverflowoccurrednginxflushesrtsigqueue,thenithandleseventsswitchingbetweenpoll()andrtsig.poll()handlesconsecutivelyallunhandledevents,whilertsigperiodicalydrainsqueuetopreventanewoverflow.Whenoverflowishandledcompley,nginxswitchestortsigmethodagain.Thertsig_overflow_eventsspecifiesthenumberofeventstobepassedviapoll().Thedefaultis16.Thertsig_overflow_testspecifiesafterwhichnumberofeventshandledbypoll()nginxwilldrainsrtsigqueue.Thedefaultis32.Thertsig_overflow_thresholdworksinLinux2.4.xonly.BeforetodrainrtsigqueuenginxlooksinakernelhowthequeueisfilledupThedefaultis1/10."rtsig_overflow_threshold3"meansSyntax:*use[kqueue|rtsig|epoll|/dev/poll|select|poll|eventport如果 你可以在这里查看可用的模型以及如何在 s=worker_processes*s=worker_processes*Sinceabrowseropens2connectionsbydefaulttoaserverandnginxusesthefds(filedescriptors)fromthesamepooltoconnecttotheupstreambackend Thisdirectiveassignsapathtobeusedfortheindicatedlocation.Notethatitmaylooksimilartothe directive,buttherootdoesn'tchange,justthefilesystempathusedfortherequest.Forlocationlocation/i/ }Therequest"/i/top.gif"willreturnthefile"/spool/w3/images/top.gif".Itispossibletousevariablesintherecementpath. directivecannotbeusedinsidearegex-specified .Ifyouneedtodothisyoumustuseacombinationof ThedirectiveenablestostorearequestbodyinaPleasenotethatthefileattherequestcompletionwillnotberemovedifthedirectiveisThisdirectivecanbeusedfordebuggingandfortheEmbeddedPerlmodule.

methodinThedirective(0.7.58+)specifieswhethertokeepthewholebodyinasinglerequestbuffer.Thedirectiveis mendedwhenusingthevariable$request_bodytoreducetheoperationsofcopying.default:*8k/16k*context:*http,server,location*ThedirectivespecifiestherequestbodybufferIftherequestbodyismorethanthebuffer,thentheentirerequestbodyorsomepartiswritteninatemporaryfile.Thedefaultsizeisequaltotwopagessize,dependingontformitiseither8Korsyntax:*_body_temp_pathdir-path[level1[level2[level3ThedirectiveassignsthedirectoryforstoringthetemporaryfilesinitwiththebodyoftheIn ahierarchyofsubdirectoriesuptothreelevelsareFor_body_temp_path_body_temp_path_temp1ThedirectorystructurewillbelikeDirectivesetsthereadtimeoutfortherequestbody Thetimeoutissetonlyifabodyisnotgetinonereadstep.Ifafterthistimethe nothing,nginxreturnserror"Requesttimeout"(408).DirectivesetstheheaderbuffersizefortherequestheaderfromFortheoverwhelmingmajorityofrequestsitiscompleysufficientabuffersizeofHoweverifabigisintherequest-headerortherequesthascomefromawap-theheadercannotbecedin1K,therefore,therequest-headeroralineofrequest-headerisnotlocatedcompleyinthisbuffernginxallocateabiggerbuffer,thesizeofthebiggerbuffercanbesetwiththeinstructionlarge__header_buffers.DirectiveassignstimeoutwithreadingofthetitleoftherequestofThetimeoutissetonlyifaheaderisnotgetinonereadstep.Ifafterthistimethesendnothing,nginxreturnserror"Requesttimeout"(408).Directiveassignsthe umacceptedbodysizeof request,indicatedbythelineintheheaderofrequest.Ifsizeisgreaterthegivenone,thenthe getstheerror"RequestEntityTooLarge"Itisnecessarytokeepinmindthatthebrowsersdonotknowhowtocorrectlyshowthisdefault:*default_typetext/in*context:*http,server,location*AssignsthedefaultMIME-typetobeusedforfileswherethestandardMIMEmapdoesn'tspecifyanything.location=.paclocation=.pacdefault_typeapplication/x-}location= d.datrewrite.default_typeapplication/x-}syntax:*directio[size|off]*default:*directiooff*ThedirectiveenablesuseofflagsO_DIRECT(BSD,Linux),F_NOCACHE(MacOSX)ordirectio()function(Solaris)forreadingfileswithsizegreaterthanspecified.Thisdirectivedisablesuseofsendfileforthisrequest.Thisdirectivemaybeusefulforbigfiles:directiodirectiosyntax:*error_pagecode[code...][=|=answer-code]uri|context:*http,server,location,ifinThedirectivespecifiestheURI,whichwillbeshowedfortheerrorsindicated. 502503=Furthermore,itispossibletochangethecodeofanswertoanother,forerror_pageerror_page404=200IfanerroneousanswerisprocessedbytheproxiedorFastCGIserverandthisservercanreturnthedifferentanswercodes,forexample,200,302,401or404,thenitispossibletohidethecodereturned: 404=Ifyouwishtoreturntheerrorcodeas-is,OMITthe=fromtheerror_page 404default:*if_modified_sinceexact*context:*http,server,location*Thedirective(0.7.24)defineshowtocomparetimeoffilemodificationandtimeinrequestheader"If-Modified-Since":off—don'tcheck"If-Modified-Since"requestheader(0.7.34);exact—exactmatch;before—filemodificationtimeshouldbelessthantimein"If-Modified-Since"requestsyntax:*indexfile[file...]*default:*indexindex.html*Directivedeterminesthefile(s)whichwillbeusedastheindex.It'spossibletousevariablesinthenameoffile.Thepresenceofthefilesischeckedintheorderoftheirenumeration.Afilewithanabsolutepathcanbeputattheend.Exampleusingavariable:indexindexindex.$geo.htmlindex.0.htmlIfyouwanttoautomaticallygenerateanindexfromadirectorylisting,useautoindexinternalindicatesthatthematchinglocationcanbeusedonlyforsocalled"internal"Forexternalrequestsitwillreturntheerror"Notfound"(404).Internalrequestsarethefollowing:requestsredirectedbytheinstructionsubrequestscreatedbythecommandincludevirtualofthe"ngx_http_ssi_module"requestschangedbytheinstructionrewriteofthe"ngx_http_rewrite_module"moduleAnexampletopreventsfetchingerrorpagesdirectly:error_pageerror_page404/404.html;location/404.html{}Nginx0.7.xintroducesanewsyntaxforinternallocationlocation/root/var/www/html;error_page404@40x;}location@40xroot}syntax:*keepalive_timeout[time]*default:*keepalive_timeout75*context:*http,server,location*Thefirstparameterassignsthetimeoutforkeep-aliveconnectionswiththe.Theserverwillcloseconnectionsafterthistime.Theoptionalsecondparameterassigns valueintheKeep-Alive:oftheresponse.Thisheadercanconvincesomebrowserstoclosetheconnection,sothattheserverdoesnothaveto.Withoutthisparameter,Keep-Alive:doesnotsenda

header(thoughthisisnotwhatmakesaconnectionTheparameterscandifferfromeachNotesonhowbrowsershandle MSIEandOperaignorethe"Keep-Alive:timeout="MSIEkeepstheconnectionaliveforabout60-65seconds,thensendsaTCPRST.Operakeepstheconnectionaliveforalongtime.MozillakeepstheconnectionaliveforNplusabout1-10seconds.KonquerorkeepstheconnectionaliveforaboutNseconds.syntax:*keepalive_requestsn*context:*http,server,location*Numberofrequestswhichcanbemadeoverakeep-alivedefault:*large__header_buffers44k/8k*context:*http,server*Directiveassignstheumnumberandsizeofbuffersforlargeheaderstoreadfromrequest.Therequestlinecannotbebiggerthanthesizeofonebuffer,ifthesendabiggerheadernginxreturnserror"RequestURItoolarge"(414).Thelongestheaderlineofrequestalsomustbenotmorethanthesizeofonebuffer,otherwisethegettheerror"Badrequest"(400).BuffersareseparatedonlyasBydefaultthesizeofonebufferisequaltothesizeofpage,dependingontformthiseither4Kor8K,ifattheendofworkingrequestconnectionconvertstostatekeep-alive,thenthesebuffersared.DirectivelimitsHTTP-methods,accessibleinsideForthelimitationcanbeusedthedirectivesofmodulesngx_http_access_moduleandlimit_exceptlimit_except{allow/32;deny}context:*http,server,location,ifinDirectiveassignsthespeedoftransmissionoftheanswerto .Speedisassignedinthebytespersecond.Limitationworksonlyforoneconnection,i.e.,if opens2connections,thentotalvelocitywillbe2timeshigherthenthelimitset.Ifitisnecessarytolimitspeedforthepartofthesattheserverlevel,basedonsomekindofcondition-thenthisdirectivedoesnotapply.Insteadyoushouldspecifythelimitbyassigningthevaluetothe$limit_ratevariable,asshownbelow:serverserverif($slow)set$limit_rate}}context:*http,server,location,ifinThedirectivelimitsspeedonlyafterthefirstpartwaslimit_rate_afterlimit_rate_after1m;limit_rate100k;syntax:*listenaddress:port[default[backlog=num|rcvbuf=size|sndbuf=size|accept_filter=filter|deferred|bind|ssl]]*Thelistendirectivespecifiestheaddressandportacceptedbytheenclosingserver{...}block.Itispossibletospecifyonlyanaddress,onlyaport,oraservernameastheaddress.listenlistenlistenlisten8000;listen*:8000;listenIPv6address(0.7.36)aresetinsquarelistenlistenlistenWhenLinux(incontrasttoBSD)bindsIPv6[::],itwillalsobindthecorrespondingIPv4address.IfothernonIPv6serverdefinitionsalreadyusedthis,thebindwillfail.Byusingexplicitaddressesinsteadof[::]thiswillnotbeaproblem.ItisalsopossibletospecifythatthislistendirectiveisonlytobindtheIPv6addresswithuseofthe"defaultipv6only=on"option.Notethatthisonlyaffectthislistendirective,thesameserver{...}blockmayverywelllistentoIPv4aswell,specifiedbyotherlistendirectives.listenlistenlisten[::]:80defaultIfonlyaddressisgiven,thedefaultportisIfthedirectivehasthedefaultparameter,thentheenclosingserver{...}blockwillbethedefaultserverfortheaddress:portpair.Thisisusefulforname-basedvirtualhostingwhereyouwishtospecifythedefaultserverblockforhostnamesthatdonotmatchany[#server_nameserver_name]directives.Iftherearenodirectiveswiththeparameter,thenthedefaultserverwillbethefirstserverblockinwhichthepairappears. directiveacceptsseveralparameters,specifictothesystemcalls .Theseparametersmustfollowthe backlog=num--isassignedparameterbacklogin-

.Bydefaultbacklogrcvbuf=size--assignedtotheparameter forthelisteningsocket.sndbuf=size--assignedtotheparameter forthelisteningsocket.accept_filter=filter--isassignednameaccept-filter..ItworksonlytoBSD,itispossibletousetwofilters-- .Onthesignal-HUPaccept-filteritispossibletochangeonlyinthequitelastversionsBSD:6.0,5.4-STABLEand4.11-STABLE.deferred--indicatestousethatpostponedaccept(2)Linux.theaidofoption

.bind--indicatesthatitisnecessaryto.forthispairofaddress:port.Thefactisthatifaredescribedseveraldirectiveslistenwiththeidenticalport,butbydifferentaddressesandoneofthedirectiveslistenlistenstoonalladdressesforthisport(:port),thennginxwillmakebind(2)onlyto:port.Itisnecessarytoconsiderthatinthiscasefordeterminingtheaddress,onwhichtheconnectionsarrive,isdonethesystemcallgetsockname().Butifareusedparametersbacklog,rcvbuf,sndbuf,accept_filterordeferred,thenitisalwaysdoneseparayforthispairofaddress:portbind(2).ssl--parameter(0.7.14)notrelatedtolisten(2)andbind(2)syscalls.butinsteadspecifiesthatconnectionsacceptedonthisportshouldworkinSSLmode.ThisallowstospecifycompactconfigurationsforserversworkingwithbothHTTPandHTTPS.Forexample:listenlistenlisten443defaultExampleoftheuseofthelistenlistendefaultaccept_filter=datareadysyntax:*location[=|~|~|^~]/uri/{...ThisdirectiveallowsdifferentconfigurationsdependingontheURI.Itcanbeconfiguredusingbothlilstringsandregularexpressions.Touseregularexpressions,youmustusetheaprefix:forcaseinsensitiveforcasesensitiveTodeterminewhichlocationdirectivematchesaparticularquery,thelilstringsarecheckedfirst.Lilstringsmatchthebeginningportionofthequeryandarecase--themostspecificmatchwillbeused(seebelowonhownginxdeterminesthis).regularexpressionsarecheckedintheorderdefinedintheconfigurationfile.Thefirstregularexpressiontomatchthequerywillstopthesearch.Ifnoregularexpressionmatchesarefound,theresultfromtheli lstringsearchisused.Therearetwowaystomodifythisbehavior.Thefirstistousetheprefix"=",whichmatchesanexactqueryonly.Ifthequerymatches,thensearchingstopsandtherequestishandled y.Forexample,iftherequest"/"occursfrequently,thenusing"location=/"willexpeditetheprocessingofthisrequest.Thesecondistousetheprefix .Thisprefixisusedwithali lstringand lsnginxtonotcheckregularexpressionsifthepathprovidedisamatch.Forinstance,"location/images/"wouldhaltsearchingifthequerybeginswith/images/-allregularexpressiondirectiveswouldnotbechecked.Tosummarize,theorderinwhichdirectivesarecheckedisasDirectiveswith prefixthatmatchthequeryexactly.Iffound,searchingAllremainingdirectiveswithconventionalstrings.Ifthismatchusedthesearchingstops.Regularexpressions,intheordertheyaredefinedintheconfiguration

If#3yieldedamatch,thatresultisused.Otherwise,thematchfrom#2isItisimportanttoknowthatnginxdoesthecomparisonagainstdecodedURIs.Forexample,ifyouwishtomatch"/images/%20/test",thenyoumustuse"/images//test"todeterminethelocationlocation=/#matchesthequery/only.[configurationA]}location/#matchesanyquery,sinceallqueriesbeginwith/,butregular#expressionsandanylongerconventionalblockswillbe#matched[configurationB}location^~/images/#matchesanyquerybeginningwith/images/andhaltssearching,#soregularexpressionswillnotbechecked.[configurationC}location~*\.(gif|jpg|jpeg)$#matchesanyrequestendingingif,jpg,orjpeg.However,all#requeststothe/images/directorywillbehandledby#ConfigurationC.[configurationD]}Example/->configuration /images/1.gif->configuration s/1.jpg->configurationNotethatyoucoulddefinethese4configurationsinanyorderandtheresultswouldremainthesame.Whilenestedlocationsareallowedbytheconfigurationfileparser,theiruseisdiscouragedandmayproduceunexpectedresults.HownginxDeterminesWhichPathMostuserswillnotneedtoknowhownginxinternallydetermineswhichpathtouse-knowthatitwillchoosethe"mostspecific"matchforyourURIinaspeedyandefficientmanner.Forthosethatarecurious,however,readon.Allpathstringsaresortedalphabetically.nginxthenproceedstosearchdownthelistlookingformatchesuntiltherequestURIhasa"higher"valuethenthecurrentstringinthesortedlist.Thisisdeterminedusingthefamilyof functions-once returns1,thensearchingstops.Oncesearchingstops,thelaststringwhichmatchedisused.Forexample,letssaywehavethefollowing//Now,letssaytheservergetsthepath"/az".nginxwouldbeginsearchdownthislist.First,"/"wouldmatch,but"/islessthan"/az"sosearchingcontinues."/a"alsomatches,but"/a"isstilllessthan"/az"sowecontinueagain."/apple"doesnotmatch.Thenextstring,"/banana",isgreaterthan"/az"sosearchingstopsandthelastmatch,"/a",wouldbeused.NamedLaterversionsofNginx(>0.7.x)haveNamedLocations.Thesearelocationblocksthatstartwithan@symbol,andaretreatedsimilartointernallocationsexceptthattheypreservetheoriginalURIoninternalredirectsforerror_pageortry_filesdirectives.locationlocation/try_files@joomla}location@joomlarewrite^(.*)$/index.php?q=$1}default:*log_not_foundon*context:*http,server,location*Thedirectiveenablesordisablesmessagesinerror_logaboutfilesnotfoundondefault:*log_subrequestoff*context:*http,server,location*Thedirectiveenablesordisablesmessagesinaccess_logaboutsub-requestssuchasrewriterulesand/orSSIrequests.default:*msie_paddingon*context:*http,server,location*Thisdirectiveenablesordisablesthethemsie_paddingfeatureforMSIEbrowsers.Whenthisisenabled,nginxwillpadthesizeoftheresponsebodytoaminimumof512bytes,forresponseswithastatuscodeaboveorequalto400.Thepaddingpreventstheactivationof"friendly"HTTPerrorpagesinMSIE,soastonothidethemore-informativeerrorpagesfromtheserver.NotethatChromium/Chromehave"friendly"HTTPerrorpagesaswell,butthisfeaturewillnotsendthemthepadding.syntax:*msie_refresh[on|off]*default:*msie_refreshoff*Thisdirectiveallowsorforbidsissuing insteadofng forsyntax:*open_file_cachemax=N[inactive=time]|Thedirectivesetsthecacheactivityon.TheseinformationcanbeOpenfiledescriptors,informationwiththeirsizeandmodificationtime;Informationabouttheexistenceofdirectories;Errorinformationwhensearchesforafile-nofile,donothaverightstoread,etc.Seealsoopen_file_cache_errorsOptionsspecifiestheumnumberofentriesinthecache.Whenthecacheoverflows,thelongest-useditems(LRU)willberemoved;-specifiesthetimewhenthecacheditemisremoved,ifithasnotbeendownloadedduringthattime,thedefaultis60seconds;prohibitsthecacheopen_file_cacheopen_file_cachemax=1000inactive=20s; open_file_cache_min_uses2; syntax:*open_file_cache_errorson|off*default:*open_file_cache_errorsoff*context:*http,server,location*ThedirectivespecifiestocacheerrorsornotwhensearchingaThedirectivedefinestheminimumusenumberofafilewithinthetimespecifiedinthedirectiveparameterinactiveinopen_file_cache.?Ifusemorethanthenumber,thefiledescriptorwillremainopeninthecache.default:*open_file_cache_valid60*context:*http,server,location*Thedirectivespecifiesthetimewhenneedtocheckthevalidityoftheinformationabouttheiteminopen_file_cache.syntax:*optimize_server_names[on|off]*default:*optimize_server_nameson*context:*http,server*Directiveactivatesordeactivatesoptimizationofhostnamechecksforname-basedvirtualInparticular,thecheckinfluencesthenameofthehostusedinredirects.Ifoptimizationison,andallname-basedserverslisteningononeaddress:portpairhaveidenticalconfiguration,thennamesarenotcheckedduringrequestexecutionandredirectsusefirstservername.Ifredirectmustusehost

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论