T086ѧϰ�� | վ��ѧԺ | �����ĵ� | ���� | Ъ���� | IP��ַ��ѯ | �������� | ���ջ��� | �����ֵ� | ���ù��� | ������Ϣ��ѯ

С�ڴ�VPS֮Nginx+PHP-fpm�߸����Ż���ѹ�����Է���

�� ����ʱ�䣺2011-01-24 | ���壺�� �� С��
[����]Nginx+PHP-fpm���ϣ����ڴ�ռ��С����������ǿ׳���ص㣬��ΪС�ڴ�VPS��վ����ѡ���ϡ�����һ����̽��һ��nginx+php-fpm�߸��ص��Ż������� ��������nginx���ò������Ż���nginx��ǰ�˽�����������������web server...

Nginx+PHP-fpm���ϣ����ڴ�ռ��С����������ǿ׳���ص㣬��ΪС�ڴ�VPS��վ����ѡ���ϡ�����һ����̽��һ��nginx+php-fpm�߸��ص��Ż�������

��������nginx���ò������Ż���nginx��ǰ�˽�����������������web server, ���ÿɵ��IJ������£�

������ʾ��nginx����

user www-data;
worker_processes  8;

#worker_processes ����8�� ����8ûʲô�ã�С��8��nginx���ܷ��Ӳ�����
worker_cpu_affinity 01 10 01 10 01 10 01 10;

#worker_cpu_affinity ��������ʹnginx���ַ��Ӷ���Cpu���������� ������������������˫��CPU�����á�01��ʾ��һ���ˣ�10��ʾ�ڶ����ˣ��������ĺ�cpu��һ���ĸ��˷ֱ���ʾΪ 0001 0010 0100 1000

error_log  /var/log/nginx/error_log crit;
pid        /var/run/nginx.pid;
worker_rlimit_nofile 10240;

#worker_rlimit_nofile ��nginx�ܴ����ļ���������������������Ҫ��������������һ�㡣

#linuxϵͳ���ļ��鿴�����Ʋ鿴���� ulimit -n ���޸������������� ulimit -HSn 65535

events
{
use epoll;

#����Ҫ�ø�Ч��event�������Ի�����������
worker_connections  10240;

#max_clients = worker_processes * worker_connections/4 �������������ļ��㹫ʽ��

}
http
{
include /etc/nginx/deny.iplist;
include       /etc/nginx/mime.types;
default_type  application/octet-stream;
server_name_in_redirect off;
server_names_hash_bucket_size 128;
server_tokens off;
client_header_buffer_size 32k;

#clientͷbuffer���Ե�Ϊ32K
large_client_header_buffers 4 32k;
client_max_body_size 8m;
sendfile        on;
tcp_nopush     on;
keepalive_timeout 65;
tcp_nodelay        off;
client_body_timeout 10;
client_header_timeout 10;
send_timeout 60;
output_buffers 1 32k;
postpone_output 1460;
open_file_cache max=1000 inactive=20s;
open_file_cache_valid    30s;
open_file_cache_min_uses 2;
open_file_cache_errors   on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 32k;
fastcgi_buffers 4 32k;
fastcgi_busy_buffers_size 32k;
fastcgi_temp_file_write_size 32k;
gzip on;
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_proxied        expired no-cache no-store private auth;
proxy_cache_path  /var/lib/nginx/cache  levels=1:2   keys_zone=staticfilecache:80m inactive=1d  max_size=2500m;
proxy_temp_path /var/lib/nginx/proxy;
proxy_connect_timeout 300;
proxy_read_timeout 120;
proxy_send_timeout 120;
proxy_buffer_size  16k;
proxy_buffers      4 16k;
upstream wordpressnginx
{
server 127.0.0.1:6000 weight=1 fail_timeout=120s;
}
include /etc/nginx/sites-enabled/*;
}

�������������棬�жദ�輰��buffer��timeout�ĵط������ǿ��Ը�����Ҫ������������Щ������buffer��Ȼ�Ǵ����ã�����Ҫ̫����16K�DZ�׼���ã��������ӵ�32�����ϼӸ���Ҳ���Dz��У��� Ҫ���ǵ���ϵͳ�ڴ��󲻴󣬹������á�timeout�dz�ʱ�������������ܷ�æ���������ӳ�ʱ�ȴ�ʱ�䣬�Ա���Ƶ������502������

gzip�DZ��뿪���ģ�reverse proxy�������������£�Ҳ����������һ �ǿ���������ӦЧ�ʣ����ǽ��ͷ�����ѹ����gzip�����������Խ�ʡ������������

nginx��Ҫ����������������

���ڿ�һ��php-fpm�����á�
[global]
pid = run/php5-fpm.pid
process_control_timeout = 5
[www]
listen = /dev/shm/php-cgi.sock
listen.allowed_clients = 127.0.0.1
user = www-data
group = www-data
pm = static
pm.max_children = 7

#���������� php-fpm���ܽ��̡�����Ҫ��ͬʱ��Ӧ�����IJ�������������ֵҪ�����ܴ󣬱���500��1000
pm.max_requests = 10000

#������Խ������������������Ӧ��Խ�󣬲�����С��������ֵҲӦ��ԽС������ʾ��php-fpm������Ӧ��10000����������֮�󣬾��Զ�����һ�½��̡�
request_terminate_timeout = 30

#��ʾ�ȴ�30���󣬽�����Щû���Զ�������php�ű������ͷ�ռ�õ���Դ��
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

С�ڴ���vps��Ȼ����ʹ��php-fpm+nginx��������ϵͳ��Ч�ʣ�����ͬʱ��Ӧ�϶��IJ������󣬵��ǵ������������ˣ�������100������10000��С�ڴ��϶���Ӧ��������cpuҲ�� ��Ϊ̫æ��������ϵͳ���ر��úܸߺܸߣ�����ʱ�������Ǿ�Ҫ��������Ӳ�������ˡ�

�ڴ�Խ��Խ�ã�CPU����Ƶ��Խ��Խ�ã�CPU��Խ��Խ�á�Ӳ��������SSD+RAID10���������ܲ����ߣ����ݰ�ȫҲ�б��ϡ�

�������ᵽ�ĸ������ò������輰����ֵ�ģ������Լ� �����ŵ�С������������Ȼ��������nginx����php-fpm���̣�����Ч����ô����

��������һ���ȽϺõ�ѹ�����Թ��ߣ�siege.

debian��ubuntu�û�����ͨ��apt-get install siege����װsiege.

siege��һ����ab.exe���Ƶ�httpѹ������������

���ǿ�����siege���������ǵ���վ�ͷ��������ܡ�

siege -r 100 -c 10 http://www.domain.com/test.php

-r �� repeat , -r 100���ظ�100�β���

-c 10�DZ�ʾģ��10���û�ͬʱ��������

��������Ҫ���Ե�URL��ַ��

���Թ����п�����ʱ��CTRL+C��ֹ���̣�siege������һ�����������ǡ�

���ǿ���ͬʱ����siege�IJ��Խ����ͼ��ӷ������ĸ�����������ϵͳѹ��״������һ�������˽��ͷ��������������԰��������жϸ����ν�����һ���������Ǽ����Ż����ã���������Ӳ����

  • ת����ע����Դ��ITѧϰ�� ��ַ��http://www.t086.com/ �����������Ƽ�������
  • �ر������� ��վ�������ر�������ֹת�ص�ר�������������¿�������ת�أ���������ע��������ԭʼ���ߡ����°�Ȩ������ԭʼ�������С����ڱ���վת�����µĸ��˺���վ�����DZ�ʾ������л�⡣������վת�ص������а�Ȩ��������ϵ���ǣ����ǻᾡ�����Ը�����
������ѯ Health Check Gulangyu
© 2017 T086ѧϰ�� - T086.com(ԭitlearner.com)
RunTime:5.87ms QueryTime:7