网站建设数据库放哪,做杂志的网站有哪些内容,展厅设计费,wordpress前端文章编辑器本文由LinuxProbe.Com团队成员岳国帅整理发布#xff0c;原文来自#xff1a;黑白。导读使用Nginx搭配PHP已有7年的经历#xff0c;这份经历让我们学会如何为高流量站点优化NGINX和PHP-fpm配置。以下正是这方面的一些提示和建议#xff1a;1. 将TCP切换为UNIX域套接字1. 将…本文由LinuxProbe.Com团队成员岳国帅整理发布原文来自黑·白。导读使用Nginx搭配PHP已有7年的经历这份经历让我们学会如何为高流量站点优化NGINX和PHP-fpm配置。以下正是这方面的一些提示和建议1. 将TCP切换为UNIX域套接字1. 将TCP切换为UNIX域套接字UNIX域套接字相比TCP套接字在loopback接口上能提供更好的性能(更少的数据拷贝和上下文切换)。但有一点需要牢记仅运行在同一台服务器上的程序可以访问UNIX域套接字(显然没有网络支持)。upstream backend{# UNIX domain socketsserver unix:/var/run/fastcgi.sock;# TCP sockets# server 127.0.0.1:8080;}2. 调整工作进程数现代计算机硬件是多处理器的NGINX可以利用多物理或虚拟处理器。多数情况下你的Web服务器都不会配置为处理多种任务(比如作为Web服务器提供服务的同时也是一个打印服务器)你可以配置NGINX使用所有可用的处理器NGINX工作进程并不是多线程的。运行以下命令可以获知你的机器有多少个处理器Linux上 -cat /proc/cpuinfo | grep processorFreeBSD上 -sysctl dev .cpu | grep location将nginx.conf文件中work_processes的值设置为机器的处理器核数。同时增大worker_connections(每个处理器核心可以处理多少个连接)的值以及将multi_accept设置为ON如果你使用的是Linux则也使用epoll# We have 16 coresworker_processes 16;# connections per workerevents{worker_connections 4096;multi_accept on;}3. 设置upstream负载均衡以我们的经验来看同一台机器上多个upstream后端相比单个upstream后端能够带来更高的吞吐量。例如如果你想支持最大1000个PHP-fpm子进程(children)可以将该数字平均分配到两个upstream后端各自处理500个PHP-fpm子进程upstream backend {server unix:/var/run/php5-fpm.sock1 weight100 max_fails5 fail_timeout5;server unix:/var/run/php5-fpm.sock2 weight100 max_fails5 fail_timeout5;}4. 禁用访问日志文件这一点影响较大因为高流量站点上的日志文件涉及大量必须在所有线程之间同步的IO操作。access_log off;log_not_found off;error_log /var/log/nginx-error.log warn;若你不能关闭访问日志文件至少应该使用缓冲access_log /var/log/nginx/access.log main buffer16k;5. 启用GZipgzip on;gzip_disable msie6;gzip_vary on;gzip_proxied any;gzip_comp_level 6;gzip_min_length 1100;gzip_buffers 16 8k;gzip_http_version 1.1;gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xmlrss text/javascript;6. 缓存被频繁访问的文件相关的信息open_file_cache max200000 inactive20s;open_file_cache_valid 30s;open_file_cache_min_uses 2;open_file_cache_errors on;7. 调整客户端超时时间client_max_body_size 500M;client_body_buffer_size 1m;client_body_timeout 15;client_header_timeout 15;keepalive_timeout 2 2;send_timeout 15;sendfile on;tcp_nopush on;tcp_nodelay on;8. 调整输出缓冲区大小fastcgi_buffers 256 16k;fastcgi_buffer_size 128k;fastcgi_connect_timeout 3s;fastcgi_send_timeout 120s;fastcgi_read_timeout 120s;reset_timedout_connection on;server_names_hash_bucket_size 100;9. /etc/sysctl.conf调优# Recycle Zombie connectionsnet.inet.tcp.fast_finwait2_recycle1net.inet.tcp.maxtcptw200000# Increase number of fileskern.maxfiles65535kern.maxfilesperproc16384# Increase page share factor per processvm.pmap.pv_entry_max54272521vm.pmap.shpgperproc20000# Increase number of connectionsvfs.vmiodirenable1kern.ipc.somaxconn3240000net.inet.tcp.rfc13231net.inet.tcp.delayed_ack0net.inet.tcp.restrict_rst1kern.ipc.maxsockbuf2097152kern.ipc.shmmax268435456# Host cachenet.inet.tcp.hostcache.hashsize4096net.inet.tcp.hostcache.cachelimit131072net.inet.tcp.hostcache.bucketlimit120# Increase number of portsnet.inet.ip.portrange.first2000net.inet.ip.portrange.last100000net.inet.ip.portrange.hifirst2000net.inet.ip.portrange.hilast100000kern.ipc.semvmx131068# Disable Ping-flood attacksnet.inet.tcp.msl2000net.inet.icmp.bmcastecho1net.inet.icmp.icmplim1net.inet.tcp.blackhole2net.inet.udp.blackhole110. 监控持续监控打开连接的数目空闲内存以及等待状态线程的数目。设置警报在超出阈值时通知你。你可以自己构建这些警报或者使用类似ServerDensity的东西。确认安装了NGINX的stub_status模块。该模块默认并不会编译进NGINX所以可能你需要重新编译NGINX -./configure --with-http_ssl_module --with-http_stub_status_module --without-mail_pop3_module--without-mail_imap_module --without-mail_smtp_modulemake install BATCHyes