1¡¢´«Í³»º´æÖ®Ò»£¨404£©
Õâ¸ö°ì·¨ÊÇ°ÑnginxµÄ404´íÎó¶¨Ïòµ½ºó¶Ë£¬È»ºóÓÃproxy_store°Ñºó¶Ë·µ»ØµÄÒ³Ãæ±£´æ¡£
ÅäÖãº
location / { root /home/html/;#Ö÷Ŀ¼ expires 1d;#ÍøÒ³µÄ¹ýÆÚʱ¼ä error_page 404 =200 /fetch$request_uri;#404¶¨Ïòµ½/fetchĿ¼Ï } location /fetch/ {#404¶¨Ïòµ½ÕâÀï internal;#Ö¸Ã÷Õâ¸öĿ¼²»ÄÜÔÚÍⲿֱ½Ó·ÃÎʵ½ expires 1d;#ÍøÒ³µÄ¹ýÆÚʱ¼ä alias /home/html/;#ÐéÄâĿ¼ÎļþϵͳµØÖ·ÒªºÍlocaion /Ò»Ö£¬proxy_store»á½«Îļþ±£´æµ½ÕâĿ¼Ï proxy_pass ;#ºó¶ËupstreamµØÖ·£¬/fetchͬʱÊÇÒ»¸ö´úÀí proxy_set_header Accept-Encoding '';#Èúó¶Ë²»Òª·µ»ØѹËõ£¨gzip»òdeflate£©µÄÄÚÈÝ£¬±£´æѹËõºóµÄÄÚÈÝ»áÒý·¢ÂÒ×Ó¡£ proxy_store on;#Ö¸¶¨nginx½«´úÀí·µ»ØµÄÎļþ±£´æ proxy_temp_path /home/tmp;#ÁÙʱĿ¼£¬Õâ¸öĿ¼ҪºÍ/home/htmlÔÚͬһ¸öÓ²ÅÌ·ÖÇøÄÚ }
ʹ ÓõÄʱºò»¹ÓÐҪעÒâÊÇnginxÒªÓÐȨÏÞÍù/home/tmpºÍ/home/htmlÏÂÓÐдÈëÎļþµÄȨÏÞ£¬ÔÚlinuxÏÂnginxÒ»°ã»áÅäÖÃ³É nobodyÓû§ÔËÐУ¬ÕâÑùÕâÁ½¸öĿ¼¾ÍÒªchown nobody£¬Éè³ÉnobodyÓû§×¨Ó㬵±È»Ò²¿ÉÒÔchmod 777£¬²»¹ýËùÓÐÓоÑéµÄϵͳ¹ÜÀíÔ±¶¼»á½¨Òé²»ÒªËæ±ãʹÓÃ777¡£
2¡¢´«Í³»º´æÖ®¶þ£¨!-e£©
ÔÀíºÍ404Ìøת»ù±¾Ò»Ö£¬µ«¸ü¼ò½àһЩ£º
location / { root /home/html/; proxy_store on; proxy_set_header Accept-Encoding ''; proxy_temp_path /home/tmp; if ( !-f $request_filename ) { proxy_pass ; } }
¿ÉÒÔ¿´µ½Õâ¸öÅäÖñÈ404½ÚÔ¼Á˲»ÉÙ´úÂ룬ËüÊÇÓÃ!-fÀ´ÅжÏÇëÇóµÄÎļþÔÚÎļþϵͳÉÏ´æ²»´æÔÚ£¬²»´æÔÚ¾Íproxy_passµ½ºó¶Ë£¬·µ»ØͬÑùÊÇÓÃproxy_store±£´æ¡£
Á½ÖÖ´«Í³»º´æ¶¼ÓÐ×Å»ù±¾Ò»ÑùµÄÓŵãºÍȱµã£º
ȱ
µã1£º²»Ö§³Ö´ø²ÎÊýµÄ¶¯Ì¬Á´½Ó£¬±ÈÈçread.php?id=1£¬ÒòΪnginxÖ»±£´æÎļþÃû£¬ËùÒÔÕâ¸öÁ´½ÓÖ»ÔÚÎļþϵͳϱ£´æΪread.php£¬ÕâÑù
Óû§·ÃÎÊread.php?id=2ʱ»á·µ»Ø²»ÕýÈ·µÄ½á¹û¡£Í¬Ê±²»Ö§³ÖÕâÖÖÐÎʽµÄÊ×Ò³ºÍ¶þ¼¶Ä¿Â¼£¬ÒòΪnginx·Ç³£ÀÏʵ£¬»á½«ÕâÑùµÄÇëÇóÕÕÁ´½ÓдÈëÎļþ
ϵͳ£¬¶øÕâ¸öÁ´½ÓÏÔÈ»ÊÇÒ»¸öĿ¼£¬ËùÒÔ±£´æʧ°Ü¡£ÕâЩÇé¿ö¶¼ÐèҪдrewrite²ÅÄÜÕýÈ·±£´æ¡£
ȱµã2£ºnginxÄÚ²¿Ã»Óлº´æ¹ýÆÚºÍÇåÀíµÄÈκλúÖÆ£¬ÕâЩ»º´æµÄÎļþ»áÓÀ¾ÃÐԵر£´æÔÚ»úÆ÷ÉÏ£¬Èç¹ûÒª»º´æµÄ¶«Î÷·Ç³£¶à£¬ÄǾͻá³Å±©Õû¸öÓ²Å̿ռ䡣Ϊ´Ë¿ÉÒÔʹÓÃÒ»¸öshell½Å±¾¶¨ÆÚÇåÀí£¬Í¬Ê±¿ÉÒÔ׫дphpµÈ¶¯Ì¬³ÌÐòÀ´×öʵʱ¸üС£
ȱµã3£ºÖ»ÄÜ»º´æ200״̬Â룬Òò´Ëºó¶Ë·µ»Ø301/302/404µÈ״̬Â붼²»»á»º´æ£¬¼ÙÈçÇ¡ºÃÓÐÒ»¸ö·ÃÎÊÁ¿ºÜ´óµÄα¾²Ì¬Á´½Ó±»É¾³ý£¬ÄǾͻ᲻ͣ´©Í¸µ¼Öºó¶Ë³ÐÔز»Ð¡Ñ¹Á¦¡£
ȱµã4£ºnginx²»»á×Ô¶¯Ñ¡ÔñÄÚ´æ»òÓ²ÅÌ×÷Ϊ´æ´¢½éÖÊ£¬Ò»ÇÐÓÉÅäÖþö¶¨£¬µ±È»ÔÚµ±Ç°µÄ²Ù×÷ϵͳÀﶼ»áÓвÙ×÷ϵͳ¼¶µÄÎļþ»º´æ»úÖÆ£¬ËùÒÔ´æÔÚÓ²ÅÌÉÏÒ²²»ÐèÒª¹ý·Öµ£ÐÄ´ó²¢·¢¶ÁÈ¡Ôì³ÉµÄioÐÔÄÜÎÊÌâ¡£
nginx ´«Í³»º´æµÄȱµãÒ²ÊÇËüºÍsquidµÈ»º´æÈí¼þµÄ²»Í¬Ö®ÌØÉ«£¬ËùÒÔÒ²¿É¿´×÷ÆäÓŵ㡣ÔÚÉú²úÓ¦ÓÃÖÐËü³£³£ÓÃ×÷ºÍsquidµÄ´îµµ£¬squid¶ÔÓÚ´ø?µÄÁ´½ÓÍù ÍùÎÞ·¨×èµ²£¬¶ønginxÄܽ«Æä·ÃÎÊÀ¹×¡£¬ÀýÈ磺?ºÍÔÚsquidÉϻᱻµ±×öÁ½¸öÁ´½Ó£¬ËùÒÔ»áÔì³ÉÁ½´Î´©Í¸£»¶ønginxÖ»»á±£´æÒ»´Î£¬ÎÞÂÛÁ´½Ó±ä³É»¹ ÊÇ£¬¾ù²»ÄÜ͸¹ýnginx»º´æ£¬´Ó¶øÓÐЧµØ±£»¤Á˺ó¶ËÖ÷»ú¡£
nginx»á·Ç³£ÀÏʵµØ½«Á´½ÓÐÎʽ±£´æµ½ÎļþϵͳÖУ¬ÕâÑù¶ÔÓÚÒ»¸öÁ´½Ó£¬¿ÉÒԺܷ½±ãµØ²éÔÄËüÔÚ»º´æ»úÆ÷ÉϵĻº´æ״̬ºÍÄÚÈÝ£¬Ò²¿ÉÒԺܷ½±ãµØºÍ±ðµÄÎļþ¹ÜÀíÆ÷ÈçrsyncµÈÅäºÏʹÓã¬ËüÍêÍêÈ«È«¾ÍÊÇÒ»¸öÎļþϵͳ½á¹¹¡£
Õâ Á½ÖÖ´«Í³»º´æ¶¼¿ÉÒÔÔÚlinuxϽ«Îļþ±£´æµ½/dev/shmÀһ°ãÎÒÒ²ÊÇÕâô×öµÄ£¬ÕâÑù¿ÉÒÔÀûÓÃϵͳÄÚ´æÀ´×ö»º´æ£¬ÀûÓÃÄÚ´æµÄ»°£¬ÇåÀí¹ýÆÚÄÚÈÝËÙ¶È ¾Í»á¿ìµÃ¶à¡£Ê¹ÓÃ/dev/shm/ʱ³ýÁËÒª°ÑtmpĿ¼ҲָÏòµ½/dev/shmÕâ¸ö·ÖÇøÍ⣬Èç¹ûÓдóÁ¿Ð¡ÎļþºÍĿ¼£¬»¹ÒªÐÞ¸ÄÒ»ÏÂÕâ¸öÄÚ´æ·ÖÇøµÄ inodeÊýÁ¿ºÍ×î´óÈÝÁ¿£º
mount -o size=2500M -o nr_inodes=480000 -o noatime,nodiratime -o remount /dev/shm
ÉÏ ÃæµÄÃüÁîÔÚһ̨ÓÐ3GÄÚ´æµÄ»úÆ÷ÉÏʹÓã¬ÒòΪ/dev/shmĬÈÏ×î´óÄÚ´æÊÇϵͳÄÚ´æµÄÒ»°ë¾ÍÊÇ1500M£¬ÕâÌõÃüÁÆäµ÷´ó³É2500M£¬Í¬Ê±shmϵ ͳinodeÊýÁ¿Ä¬ÈÏÇé¿öÏ¿ÉÄÜÊDz»¹»Óõģ¬µ«ÓÐȤµÄÊÇËü¿ÉÒÔËæÒâµ÷½Ú£¬ÕâÀïµ÷½ÚΪ480000±£ÊØÁ˵㣬µ«Ò²»ù±¾¹»ÓÃÁË¡£
3¡¢»ùÓÚmemcachedµÄ»º´æ
nginx¶ÔmemcachedÓÐËùÖ§³Ö£¬µ«Êǹ¦Äܲ¢²»ÊÇÌرð֮ǿ£¬ÐÔÄÜÉÏ»¹ÊǷdz£Ö®ÓÅÐã¡£
location /mem/ { if ( $uri ~ "^/mem/([0-9A-Za-z_]*)$" ) { set $memcached_key "$1"; memcached_pass 192.168.1.2:11211; } expires 70; }
Õâ¸öÅäÖûὫָÃ÷µ½memcachedµÄabcÕâ¸ökeyȥȡÊý¾Ý¡£
nginxĿǰûÓÐдÈëmemcachedµÄÈκλúÖÆ£¬ËùÒÔÒªÍùmemcachedÀïдÈëÊý¾ÝµÃÓúǫ́µÄ¶¯Ì¬ÓïÑÔÍê³É£¬¿ÉÒÔÀûÓÃ404¶¨Ïòµ½ºó¶ËȥдÈëÊý¾Ý¡£
4¡¢»ùÓÚµÚÈý·½²å¼þncache
ncacheÊÇÐÂÀËÐֵܿª·¢µÄÒ»¸ö²»´íµÄÏîÄ¿£¬ËüÀûÓÃnginxºÍmemcachedʵÏÖÁËÒ»²¿·ÖÀàËÆsquid»º´æµÄ¹¦ÄÜ£¬ÎÒ²¢Ã»ÓÐʹÓÃÕâ¸ö²å¼þµÄ¾Ñ飬¿ÉÒԲο¼£º
5¡¢nginxпª·¢µÄproxy_cache¹¦ÄÜ
´Ónginx-0.7.44°æ¿ªÊ¼£¬nginxÖ§³ÖÁËÀàËÆsquid½ÏΪÕý¹æµÄcache¹¦ÄÜ£¬Ä¿Ç°»¹´¦ÓÚ¿ª·¢½×¶Î£¬Ö§³ÖÏ൱ÓÐÏÞ£¬Õâ¸ö»º´æÊÇ°ÑÁ´½ÓÓÃmd5±àÂëhashºó±£´æ£¬ËùÒÔËü¿ÉÒÔÖ§³ÖÈÎÒâÁ´½Ó£¬Í¬Ê±Ò²Ö§³Ö404/301/302ÕâÑùµÄ·Ç200״̬¡£
ÅäÖãº
Ê×ÏÈÅäÖÃÒ»¸öcache¿Õ¼ä£º
proxy_cache_path /path/to/cache levels=1:2 keys_zone=NAME:10m inactive=5m max_size=2m clean_time=1m;
×¢ ÒâÕâ¸öÅäÖÃÊÇÔÚserver±êÇ©Í⣬levelsÖ¸¶¨¸Ã»º´æ¿Õ¼äÓÐÁ½²ãhashĿ¼£¬µÚÒ»²ãĿ¼ÊÇ1¸ö×Öĸ£¬µÚ¶þ²ãΪ2¸ö×Öĸ£¬±£´æµÄÎļþÃû¾Í»áÀàËÆ /path/to/cache/c/29/b7f54b2df7773722d382f4809d65029c£»keys_zoneΪÕâ¸ö¿Õ¼äÆð¸öÃû ×Ö£¬10mÖ¸¿Õ¼ä´óСΪ10MB£»inactiveµÄ5mÖ¸»º´æĬÈÏʱ³¤5·ÖÖÓ£»max_sizeµÄ2mÊÇÖ¸µ¥¸öÎļþ³¬¹ý2mµÄ¾Í²»»º ´æ£»clean_timeÖ¸¶¨Ò»·ÖÖÓÇåÀíÒ»´Î»º´æ¡£
location / { proxy_pass ; proxy_cache NAME;#ʹÓÃNAMEÕâ¸ökeys_zone proxy_cache_valid 200 302 1h;#200ºÍ302״̬Âë±£´æ1Сʱ proxy_cache_valid 301 1d;#301״̬Âë±£´æÒ»Ìì proxy_cache_valid any 1m;#ÆäËüµÄ±£´æÒ»·ÖÖÓ }
ÍƼöÐÅÏ¢
- linuxÃüÁîѧϰ±Ê¼Ç£¨11£©£ºnlÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨5£©£ºrmÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨4£©£ºmkdirÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨1£©£ºlsÃüÁî
- ½«CentosµÄyumÔ´¸ü»»Îª¹úÄڵİ¢ÀïÔÆÔ´
- ʹÓÃNginxÌí¼Óheader·ÀÖ¹ÍøÒ³±»frame
- linuxϼÓËÙscp´«Êä´óÎļþµÄËÙ¶È
- linuxϵͳÉ϶ÔnginxÈÕÖ¾·Ö¸î´¦Àí
- lnmp/nginxϵͳÕæÕýÓÐЧµÄͼƬ·ÀµÁÁ´ÍêÕûÉèÖÃÏê½â
- Í»ÆÆÊ®Íò²¢·¢µÄNginxµÄÅäÖü°ÓÅ»¯
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- ²éÕÒ²¢É¾³ý.svnĿ¼Îļþ
- redis ÆßÖÖÊý¾ÝÀàÐ͵ÄʹÓó¡¾°
- linux ÏÂÎļþ¸´ÖƵ½windowsÏÂÂÒÂëµÄ½â¾ö°ì·¨
- nginx³öÏÖ502 upstream sent too big he....
- linuxÏÂsudoÅäÖÃÏê½â
- linuxÃüÁîѧϰ±Ê¼Ç£¨15£©£ºtailÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨14£©£ºheadÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨13£©£ºlessÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨12£©£ºmoreÃüÁî
- ¼ÓÃÜËã·¨±È½Ï3DES AES RSA ECC MD5 SHA1µÈ
ÆÀÂÛ