Í»ÆÆÊ®Íò²¢·¢µÄNginxµÄÅäÖü°ÓÅ»¯(2)
Ò»¸ö¼òµ¥µÄnginxÓÅ»¯ÅäÖÃÎļþ
user www www; worker_processes 8; worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000; error_log /www/log/nginx_error.log crit; pid /usr/local/nginx/nginx.pid; worker_rlimit_nofile 204800; events { use epoll; worker_connections 204800; } http { include mime.types; default_type application/octet-stream; charset utf-8; server_names_hash_bucket_size 128; client_header_buffer_size 2k; large_client_header_buffers 4 4k; client_max_body_size 8m; sendfile on; tcp_nopush on; keepalive_timeout 60; fastcgi_cache_path /usr/local/nginx/fastcgi_cache levels=1:2 keys_zone=TEST:10m inactive=5m; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 16k; fastcgi_buffers 16 16k; fastcgi_busy_buffers_size 16k; fastcgi_temp_file_write_size 16k; fastcgi_cache TEST; fastcgi_cache_valid 200 302 1h; fastcgi_cache_valid 301 1d; fastcgi_cache_valid any 1m; fastcgi_cache_min_uses 1; fastcgi_cache_use_stale error timeout invalid_header http_500; open_file_cache max=204800 inactive=20s; open_file_cache_min_uses 1; open_file_cache_valid 30s; tcp_nodelay on; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; server { listen 8080; server_name ad.test.com; index index.php index.htm; root /www/html/; location /status { stub_status on; } location ~ .*\.(php|php5)?$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fcgi.conf; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ { expires 30d; } log_format access '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" $http_x_forwarded_for'; access_log /www/log/access.log access; } }
¹ØÓÚFastCGIµÄ¼¸¸öÖ¸Áî
fastcgi_cache_path /usr/local/nginx/fastcgi_cache levels=1:2 keys_zone=TEST:10m inactive=5m;
Õâ¸öÖ¸ÁîΪFastCGI»º´æÖ¸¶¨Ò»¸ö·¾¶£¬Ä¿Â¼½á¹¹µÈ¼¶£¬¹Ø¼ü×ÖÇøÓò´æ´¢Ê±¼äºÍ·Ç»î¶¯É¾³ýʱ¼ä¡£
fastcgi_connect_timeout 300;
Ö¸¶¨Á¬½Óµ½ºó¶ËFastCGIµÄ³¬Ê±Ê±¼ä¡£
fastcgi_send_timeout 300;
ÏòFastCGI´«ËÍÇëÇóµÄ³¬Ê±Ê±¼ä£¬Õâ¸öÖµÊÇÖ¸ÒѾÍê³ÉÁ½´ÎÎÕÊÖºóÏòFastCGI´«ËÍÇëÇóµÄ³¬Ê±Ê±¼ä¡£
fastcgi_read_timeout 300;
½ÓÊÕFastCGIÓ¦´ðµÄ³¬Ê±Ê±¼ä£¬Õâ¸öÖµÊÇÖ¸ÒѾÍê³ÉÁ½´ÎÎÕÊÖºó½ÓÊÕFastCGIÓ¦´ðµÄ³¬Ê±Ê±¼ä¡£
fastcgi_buffer_size 16k;
Ö¸¶¨¶ÁÈ¡FastCGIÓ¦´ðµÚÒ»²¿·ÖÐèÒªÓöà´óµÄ»º³åÇø£¬ÕâÀï¿ÉÒÔÉèÖÃΪfastcgi_buffersÖ¸ÁîÖ¸¶¨µÄ»º³åÇø´óС£¬ÉÏÃæµÄÖ¸ÁîÖ¸¶¨Ëü½«Ê¹ÓÃ1¸ö16kµÄ»º³åÇøÈ¥¶ÁÈ¡Ó¦´ðµÄµÚÒ»²¿·Ö£¬¼´Ó¦´ðÍ·£¬ÆäʵÕâ¸öÓ¦´ðÍ·Ò»°ãÇé¿ö϶¼ºÜС£¨²»»á³¬¹ý1k£©£¬µ«ÊÇÄãÈç¹ûÔÚfastcgi_buffersÖ¸ÁîÖÐÖ¸¶¨ÁË»º³åÇøµÄ´óС£¬ÄÇôËüÒ²»á·ÖÅäÒ»¸öfastcgi_buffersÖ¸¶¨µÄ»º³åÇø´óСȥ»º´æ¡£
fastcgi_buffers 16 16k;
Ö¸¶¨±¾µØÐèÒªÓöàÉٺͶà´óµÄ»º³åÇøÀ´»º³åFastCGIµÄÓ¦´ð£¬ÈçÉÏËùʾ£¬Èç¹ûÒ»¸öphp½Å±¾Ëù²úÉúµÄÒ³Ãæ´óСΪ256k£¬Ôò»áΪÆä·ÖÅä16¸ö16kµÄ»º³åÇøÀ´»º´æ£¬Èç¹û´óÓÚ256k£¬Ôö´óÓÚ256kµÄ²¿·Ö»á»º´æµ½fastcgi_tempÖ¸¶¨µÄ·¾¶ÖУ¬µ±È»Õâ¶Ô·þÎñÆ÷¸ºÔØÀ´ËµÊDz»Ã÷Öǵķ½°¸£¬ÒòΪÄÚ´æÖд¦ÀíÊý¾ÝËÙ¶ÈÒª¿ìÓÚÓ²ÅÌ£¬Í¨³£Õâ¸öÖµµÄÉèÖÃÓ¦¸ÃÑ¡ÔñÒ»¸öÄãµÄÕ¾µãÖеÄphp½Å±¾Ëù²úÉúµÄÒ³Ãæ´óСµÄÖмäÖµ£¬±ÈÈçÄãµÄÕ¾µã´ó²¿·Ö½Å±¾Ëù²úÉúµÄÒ³Ãæ´óСΪ256k¾Í¿ÉÒÔ°ÑÕâ¸öÖµÉèÖÃΪ16 16k£¬»òÕß4 64k »òÕß64 4k£¬µ«ºÜÏÔÈ»£¬ºóÁ½ÖÖ²¢²»ÊǺõÄÉèÖ÷½·¨£¬ÒòΪÈç¹û²úÉúµÄÒ³ÃæÖ»ÓÐ32k£¬Èç¹ûÓÃ4 64kËü»á·ÖÅä1¸ö64kµÄ»º³åÇøÈ¥»º´æ£¬¶øÈç¹ûʹÓÃ64 4kËü»á·ÖÅä8¸ö4kµÄ»º³åÇøÈ¥»º´æ£¬¶øÈç¹ûʹÓÃ16 16kÔòËü»á·ÖÅä2¸ö16kÈ¥»º´æÒ³Ã棬ÕâÑù¿´ÆðÀ´Ëƺõ¸ü¼ÓºÏÀí¡£
fastcgi_busy_buffers_size 32k;
Õâ¸öÖ¸ÁîÎÒÒ²²»ÖªµÀÊÇ×öʲôÓã¬Ö»ÖªµÀĬÈÏÖµÊÇfastcgi_buffersµÄÁ½±¶¡£
fastcgi_temp_file_write_size 32k;
ÔÚдÈëfastcgi_temp_pathʱ½«Óöà´óµÄÊý¾Ý¿é£¬Ä¬ÈÏÖµÊÇfastcgi_buffersµÄÁ½±¶¡£
fastcgi_cache TEST
¿ªÆôFastCGI»º´æ²¢ÇÒΪÆäÖƶ¨Ò»¸öÃû³Æ¡£¸öÈ˸оõ¿ªÆô»º´æ·Ç³£ÓÐÓ㬿ÉÒÔÓÐЧ½µµÍCPU¸ºÔØ£¬²¢ÇÒ·ÀÖ¹502´íÎó¡£µ«ÊÇÕâ¸ö»º´æ»áÒýÆðºÜ¶àÎÊÌ⣬ÒòΪËü»º´æµÄÊǶ¯Ì¬Ò³Ãæ¡£¾ßÌåʹÓû¹Ðè¸ù¾Ý×Ô¼ºµÄÐèÇó¡£
fastcgi_cache_valid 200 302 1h; fastcgi_cache_valid 301 1d; fastcgi_cache_valid any 1m;
Ϊָ¶¨µÄÓ¦´ð´úÂëÖ¸¶¨»º´æʱ¼ä£¬ÈçÉÏÀýÖн«200£¬302Ó¦´ð»º´æһСʱ£¬301Ó¦´ð»º´æ1Ì죬ÆäËûΪ1·ÖÖÓ¡£
fastcgi_cache_min_uses 1;
»º´æÔÚfastcgi_cache_pathÖ¸Áîinactive²ÎÊýֵʱ¼äÄÚµÄ×îÉÙʹÓôÎÊý£¬ÈçÉÏÀý£¬Èç¹ûÔÚ5·ÖÖÓÄÚijÎļþ1´ÎҲûÓб»Ê¹Óã¬ÄÇôÕâ¸öÎļþ½«±»ÒƳý¡£
fastcgi_cache_use_stale error timeout invalid_header http_500;
²»ÖªµÀÕâ¸ö²ÎÊýµÄ×÷Ó㬲ÂÏëÓ¦¸ÃÊÇÈÃnginxÖªµÀÄÄЩÀàÐ͵Ļº´æÊÇûÓõġ£ ÒÔÉÏΪnginxÖÐFastCGIÏà¹Ø²ÎÊý£¬ÁíÍ⣬FastCGI×ÔÉíÒ²ÓÐһЩÅäÖÃÐèÒª½øÐÐÓÅ»¯£¬Èç¹ûÄãʹÓÃphp-fpmÀ´¹ÜÀíFastCGI£¬¿ÉÒÔÐÞ¸ÄÅäÖÃÎļþÖеÄÒÔÏÂÖµ£º
<value name="max_children">60</value>
ͬʱ´¦ÀíµÄ²¢·¢ÇëÇóÊý£¬¼´Ëü½«¿ªÆô×î¶à60¸ö×ÓÏß³ÌÀ´´¦Àí²¢·¢Á¬½Ó¡£
<value name="rlimit_files">102400</value>
×î¶à´ò¿ªÎļþÊý¡£
<value name="max_requests">204800</value>
ÿ¸ö½ø³ÌÔÚÖØÖÃ֮ǰÄܹ»Ö´ÐеÄ×î¶àÇëÇóÊý¡£
¼¸ÕŲâÊÔ½á¹û
¾²Ì¬Ò³ÃæΪÎÒÔÚsquidÅäÖÃ4W²¢·¢ÄÇƪÎÄÕÂÖÐÌáµ½µÄ²âÊÔÎļþ£¬ÏÂͼΪͬʱÔÚ6̨»úÆ÷ÔËÐÐwebbench -c 30000 -t 600 http://ad.test.com:8080/index.htmlÃüÁîºóµÄ²âÊÔ½á¹û£º
ʹÓÃnetstat¹ýÂ˺óµÄÁ¬½ÓÊý£º
phpÒ³ÃæÔÚstatusÖеĽá¹û£¨phpÒ³ÃæΪµ÷ÓÃphpinfo£©£º
phpÒ³ÃæÔÚnetstat¹ýÂ˺óµÄÁ¬½ÓÊý£º
δʹÓÃFastCGI»º´æ֮ǰµÄ·þÎñÆ÷¸ºÔØ£º
´Ëʱ´ò¿ªphpÒ³ÃæÒѾÓÐЩÀ§ÄÑ£¬ÐèÒª½øÐжà´ÎˢвÅÄÜ´ò¿ª¡£ÉÏͼÖÐcpu0¸ºÔØÆ«µÍÊÇÒòΪ²âÊÔʱ½«Íø¿¨ÖжÏÇëÇóÈ«²¿·ÖÅäµ½cpu0ÉÏ£¬²¢ÇÒÔÚnginxÖпªÆô7¸ö½ø³Ì·Ö±ðÖƶ¨µ½cpu1-7¡£
ʹÓÃFastCGI»º´æÖ®ºó£º
´Ëʱ¿ÉÒÔºÜÇáËɵĴò¿ªphpÒ³Ãæ¡£
Õâ¸ö²âÊÔ²¢Ã»ÓÐÁ¬½Óµ½ÈκÎÊý¾Ý¿â£¬ËùÒÔ²¢Ã»ÓÐʲô²Î¿¼¼ÛÖµ£¬²»¹ý²»ÖªµÀÉÏÊö²âÊÔÊÇ·ñÒѾµ½´ï¼«ÏÞ£¬¸ù¾ÝÄÚ´æºÍcpuµÄʹÓÃÇé¿öÀ´¿´ËƺõûÓУ¬µ«ÊÇÒѾûÓжàÓàµÄ»ú×ÓÀ´ÈÃÎÒÔËÐÐwebbenchÁË¡£
ÍƼöÐÅÏ¢
- 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µÈ
ÆÀÂÛ