1、nginx优化 vi /usr/local/webserver/nginx/conf/nginx.conf #Nginx每个进程耗费10M~12M内存,这里只开启一个Nginx进程,节省内存。 worker_processes 1; #对网页文件、CSS、JS、XML等启动gzip压缩,减少数据传输量,提高访问速度。 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; location ~ .*\.(php|php5)?$ { #将Nginx与FastCGI的通信方式由TCP改为Unix Socket。TCP在高并发访问下比Unix Socket稳定,但Unix Socket速度要比TCP快。 fastcgi_pass unix:/tmp/php-cgi.sock; #fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fcgi.conf; } location ~ /read.php { #将Nginx与FastCGI的通信方式由TCP改为Unix Socket。TCP在高并发访问下比Unix Socket稳定,但Unix Socket速度要比TCP快。 fastcgi_pass unix:/tmp/php-cgi.sock; #fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fcgi.conf; } #博客的图片较多,更改较少,将它们在浏览器本地缓存15天,可以提高下次打开我博客的页面加载速度。 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 15d; } #博客会加载很多JavaScript、CSS,将它们在浏览器本地缓存1天,访问者在看完一篇文章或一页后,再看另一篇文件或另一页的内容,无需从服务器再次下载相同的JavaScript、CSS,提高了页面显示速度。 location ~ .*\.(js|css)?$ { expires 1d; } 2、PHP优化 vi /usr/local/webserver/php/etc/php.ini php.ini 配置文件中关于eAcelerator的优化。只使用1M共享内存,删除所有在{zh1}3600秒内无法存取的脚本缓存,用磁盘辅助进行缓存。 根据内容增加或者修改 eaccelerator.shm_size="1" eaccelerator.shm_ttl="3600" eaccelerator.shm_prune_period="3600" eaccelerator.keys = "disk_only" eaccelerator.sessions = "disk_only" eaccelerator.content = "disk_only" PHP-FPM优化 vim /usr/local/webserver/php/etc/php-fpm.conf 一是修改以下一行,将启动的php-cgi进程数由原来的128个改为5个: <value name="max_children">5</value> 二是修改以下一行,将TCP模式改为Unix Socket模式: <value name="listen_address">/tmp/php-cgi.sock</value> 3、MYSQL优化 vi /data0/mysql/3306/my.cnf 根据自己的情况改吧 [client] port = 3306 socket = /tmp/mysql.sock [mysql] prompt="(\u:s135:)[\d]> " no-auto-rehash [mysqld] user = mysql port = 3306 socket = /tmp/mysql.sock basedir = /usr/local/webserver/mysql datadir = /usr/local/webserver/mysql/data open_files_limit = 600 back_log = 20 max_connections = 100 max_connect_errors = 200 table_cache = 60 external-locking = FALSE max_allowed_packet = 16M sort_buffer_size = 128K join_buffer_size = 128K thread_cache_size = 10 thread_concurrency = 8 query_cache_size = 0M query_cache_limit = 2M query_cache_min_res_unit = 2k default_table_type = MyISAM thread_stack = 192K transaction_isolation = READ-UNCOMMITTED tmp_table_size = 512K max_heap_table_size = 32M /usr/local/webserver/mysql/data/slow.log /usr/local/webserver/mysql/data/error.log long_query_time = 1 log_long_format server-id = 1 #log-bin = /usr/local/mysql/data/binlog binlog_cache_size = 2M max_binlog_cache_size = 4M max_binlog_size = 512M expire_logs_days = 7 key_buffer_size = 4M read_buffer_size = 1M read_rnd_buffer_size = 2M bulk_insert_buffer_size = 2M myisam_sort_buffer_size = 4M myisam_max_sort_file_size = 10G myisam_max_extra_sort_file_size = 10G myisam_repair_threads = 1 myisam_recover [mysqldump] quick max_allowed_packet = 16M |