Nginx 0.8.x + php 5.2.13 (fast cgi) setup web server
Upcoming SlideShare
Loading in...5
×
 

Nginx 0.8.x + php 5.2.13 (fast cgi) setup web server

on

  • 1,898 views

nginx [engine x] is a HTTP and reverse proxy server, as well as a mail proxy server written by Igor Sysoev. It has been running for more than five years on many heavily loaded Russian sites including ...

nginx [engine x] is a HTTP and reverse proxy server, as well as a mail proxy server written by Igor Sysoev. It has been running for more than five years on many heavily loaded Russian sites including Rambler (RamblerMedia.com).

Statistics

Views

Total Views
1,898
Views on SlideShare
1,897
Embed Views
1

Actions

Likes
1
Downloads
45
Comments
0

1 Embed 1

http://www.slideshare.net 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Nginx 0.8.x + php 5.2.13 (fast cgi) setup web server Nginx 0.8.x + php 5.2.13 (fast cgi) setup web server Document Transcript

  • Nginx 0.8.x + PHP 5.2.13 (FastCGI) setup Web servernginx [engine x] is a HTTP and reverse proxy server, as well as a mail proxy server written by IgorSysoev. It has been running for more than five years on many heavily loaded Russian sitesincludingRambler (RamblerMedia.com). According to Netcraft nginx served or proxied 4.70% busiestsites in April 2010. Here are some of success stories: FastMail.FM, WordPress.com.In the case of highly concurrent connections, Nginx Apache server is a good substitute. Nginx also canserve as a layer 7 load balancing server to use. According to my test results, Nginx 0.8.46 + PHP 5.2.14(FastCGI) can withstand more than 30,000 concurrent connections, equivalent to Apache under thesame 10 times.In my experience, 4GB of RAM + Apache (prefork model) generally can only handle 3,000 concurrentconnections, as they will occupy more than 3GB of memory, have to 1GB of memory reserved for thesystem. I have had two Apache servers, as set in the configuration file MaxClients to 4000, when thenumber of concurrent connections to Apache during 3800, resulting in server memory and Swap spacewith full collapse.This station Nginx 0.8.46 + PHP 5.2.14 (FastCGI) server 30 000 concurrent connections, the opening 10Nginx process consumes 150M of memory (15M * 10 = 150M), open 64 php-cgi process consumes1280M memory (20M * 64 = 1280M), plus the memory consumed by the system itself, a totalconsumption of less than 2GB of memory. If the server memory is smaller, can only open 25 php-cgiprocess php-cgi so the total amount of memory consumed only 500M.In the 30,000 concurrent connections, the access to Nginx 0.8.46 + PHP 5.2.14 (FastCGI) PHP serverprocess is still fast. The figure below shows the status of Nginx monitoring page shows the number ofactive connections for the 28457 (on the monitoring page Nginx configuration, will be given in thisarticle continues the Nginx configuration file specify):I have two production environment Nginx + PHP5 (FastCGI) server, running more than a pure PHPgeneral complex dynamic process, a single Nginx + PHP5 (FastCGI) server running PHP dynamic iscapable of more than “700 r/s “can take 60 million per day (700 * 60 * 60 * 24 = 60.48 million) of visits,the server’s system load is not high:
  • The following is 100 concurrent connections to the pressure were the same production environmentunder load balancer to provide the same service on two servers, one for the Nginx, another for theApache, Nginx number of requests per second is twice the Apache more, Nginx server system load,CPU usage much lower than the Apache:You can open connections to 10,000 ~ 30,000, to pressure Nginx and Apache on the phpinfo.php, it isbrowser access Nginx on phpinfo.php all normal, and access to Apache server phpinfo.php, is the pagecan not be displayed. 4G of RAM, even if re-optimization, Apache and making it difficult “webbench-c30000-t 60 http://xxx.xxx.xxx.xxx/phpinfo.php” under the pressure of the normal access, and adjust theparameters optimized The Nginx can.Note: webbench do stress testing, the software itself will consume CPU and memory resources, in orderto test accuracy, please webbench installed on another server.The results :##### Nginx + PHP #####[root@localhost webbench-1.5]# webbench -c 100 -t 30 http://192.168.1.21/phpinfo.phpWebbench – Simple Web Benchmark 1.5Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.Benchmarking: GET http://192.168.1.21/phpinfo.php100 clients, running 30 sec.Speed=102450 pages/min, 16490596 bytes/sec.Requests: 51225 susceed, 0 failed.top – 14:06:13 up 27 days, 2:25, 2 users, load average: 14.57, 9.89, 6.51Tasks: 287 total, 4 running, 283 sleeping, 0 stopped, 0 zombieCpu(s): 49.9% us, 6.7% sy, 0.0% ni, 41.4% id, 1.1% wa, 0.1% hi, 0.8% siMem: 6230016k total, 2959468k used, 3270548k free, 635992k buffersSwap: 2031608k total, 3696k used, 2027912k free, 1231444k cachedThe results :##### Apache + PHP #####[root@localhost webbench-1.5]# webbench -c 100 -t 30 http://192.168.1.27/phpinfo.phpWebbench – Simple Web Benchmark 1.5Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.Benchmarking: GET http://192.168.1.27/phpinfo.php100 clients, running 30 sec.Speed=42184 pages/min, 31512914 bytes/sec.Requests: 21092 susceed, 0 failed.top – 14:06:20 up 27 days, 2:13, 2 users, load average: 62.15, 26.36, 13.42Tasks: 318 total, 7 running, 310 sleeping, 0 stopped, 1 zombieCpu(s): 80.4% us, 10.6% sy, 0.0% ni, 7.9% id, 0.1% wa, 0.1% hi, 0.9% siMem: 6230016k total, 3075948k used, 3154068k free, 379896k buffersSwap: 2031608k total, 12592k used, 2019016k free, 1117868k cachedWhy Nginx’s performance is much higher than Apache? Thanks to Nginx to use the latest epoll (Linux2.6 kernel) and kqueue (freebsd) network I/O model, but Apache is using a traditional select models.
  • Currently under Linux can withstand high concurrent access of the Squid, Memcached have adoptedthe epoll network I/O model.Installation steps:(System requirements: Linux 2.6 + kernel, the Linux operating system in this article CentOS 5.3, RedHatAS4 on the other also in the successful installation)First, access to relevant open source:1 .【 CentOS Linux】 CentOS Linux system using yum command that comes with the installation,upgrade the required libraries (RedHat and other Linux distributions can be found from theinstallation CD in the library of the RPM package to install):sudo -sLANG=Cyum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devellibxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncursesncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel opensslopenssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers2, RedHat Linux】 RedHat and other Linux distributions can be found from the installation CD in 【the library of the RPM package (prior to a similar “rpm-qa | grep libjpeg” the command to seewhether there needed to RPM package, usually ” xxx-devel “does not exist, need to install).RedHat can use the RPM package to install CentOS(1) RPM Packagehttp://rpm.pbone.net/http://www.rpmfind.net/(2) RedHat AS4 system environment, usually lack the support package is installed:a. i386libjpeg-devel-6b-33.i386.rpmfreetype-devel-2.1.9-1.i386.rpmlibpng-devel-1.2.7-1.i386.rpmb. x86_64libjpeg-devel-6b-33.x86_64.rpmfreetype-devel-2.1.9-1.x86_64.rpmlibpng-devel-1.2.7-1.x86_64.rpm3, Download source code package:mkdir -p /data0/softwarecd /data0/softwarewget http://sysoev.ru/nginx/nginx-0.8.46.tar.gzwget http://www.php.net/get/php-5.2.14.tar.gz/from/this/mirrorwget http://php-fpm.org/downloads/php-5.2.14-fpm-0.5.14.diff.gzwget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.3-m3.tar.gz/from/http://mysql.he.net/wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
  • wget http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0wget http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0wget http://pecl.php.net/get/memcache-2.2.5.tgzwget http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.10.tar.gzwget http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgzwget http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gzwget http://pecl.php.net/get/imagick-2.3.0.tgzSecond, install PHP 5.2.14 (FastCGI mode)1, build the support needed to install PHP 5.2.14 package:tar zxvf libiconv-1.13.1.tar.gzcd libiconv-1.13.1/./configure –prefix=/usr/localmakemake installcd ../tar zxvf libmcrypt-2.5.8.tar.gzcd libmcrypt-2.5.8/./configuremakemake install/sbin/ldconfigcd libltdl/./configure –enable-ltdl-installmakemake installcd ../../tar zxvf mhash-0.9.9.9.tar.gzcd mhash-0.9.9.9/./configuremakemake installcd ../ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.laln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.soln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
  • ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.laln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.soln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-configtar zxvf mcrypt-2.6.8.tar.gzcd mcrypt-2.6.8//sbin/ldconfig./configuremakemake installcd ../2, compile install MySQL 5.5.3-m3/usr/sbin/groupadd mysql/usr/sbin/useradd -g mysql mysqltar zxvf mysql-5.5.3-m3.tar.gzcd mysql-5.5.3-m3/./configure –prefix=/usr/local/webserver/mysql/ –enable-assembler –with-extra-charsets=complex –enable-thread-safe-client –with-big-tables –with-readline –with-ssl –with-embedded-server –enable-local-infile –with-plugins=partition,innobase,myisammrgmake && make installchmod +w /usr/local/webserver/mysqlchown -R mysql:mysql /usr/local/webserver/mysqlcd ../Note: The following additional steps, if you would like to run the MySQL database server, perform thefollowing steps. If you just want to make PHP support for MySQL, be able to connect to other servers onthe MySQL database, then the following two steps need to performA, create a MySQL database storage directory:mkdir -p /data0/mysql/3306/data/mkdir -p /data0/mysql/3306/binlog/mkdir -p /data0/mysql/3306/relaylog/chown -R mysql:mysql /data0/mysql/B,Establish a data table:/usr/local/webserver/mysql/bin/mysql_install_db –basedir=/usr/local/webserver/mysql –datadir=/data0/mysql/3306/data –user=mysqlC,Create my.cnf configuration filevi /data0/mysql/3306/my.cnfEnter the following:
  • [client]character-set-server = utf8port = 3306socket = /tmp/mysql.sock[mysqld]character-set-server = utf8replicate-ignore-db = mysqlreplicate-ignore-db = testreplicate-ignore-db = information_schemauser = mysqlport = 3306socket = /tmp/mysql.sockbasedir = /usr/local/webserver/mysqldatadir = /data0/mysql/3306/datalog-error = /data0/mysql/3306/mysql_error.logpid-file = /data0/mysql/3306/mysql.pidopen_files_limit = 10240back_log = 600max_connections = 5000max_connect_errors = 6000table_cache = 614external-locking = FALSEmax_allowed_packet = 32Msort_buffer_size = 1Mjoin_buffer_size = 1Mthread_cache_size = 300#thread_concurrency = 8query_cache_size = 512Mquery_cache_limit = 2Mquery_cache_min_res_unit = 2kdefault-storage-engine = MyISAMthread_stack = 192Ktransaction_isolation = READ-COMMITTEDtmp_table_size = 246Mmax_heap_table_size = 246Mlong_query_time = 3log-slave-updateslog-bin = /data0/mysql/3306/binlog/binlogbinlog_cache_size = 4Mbinlog_format = MIXEDmax_binlog_cache_size = 8Mmax_binlog_size = 1Grelay-log-index = /data0/mysql/3306/relaylog/relaylogrelay-log-info-file = /data0/mysql/3306/relaylog/relaylog
  • relay-log = /data0/mysql/3306/relaylog/relaylogexpire_logs_days = 30key_buffer_size = 256Mread_buffer_size = 1Mread_rnd_buffer_size = 16Mbulk_insert_buffer_size = 64Mmyisam_sort_buffer_size = 128Mmyisam_max_sort_file_size = 10Gmyisam_repair_threads = 1myisam_recoverinteractive_timeout = 120wait_timeout = 120skip-name-resolve#master-connect-retry = 10slave-skip-errors = 1032,1062,126,1114,1146,1048,1396#master-host = 192.168.1.2#master-user = username#master-password = password#master-port = 3306server-id = 1innodb_additional_mem_pool_size = 16Minnodb_buffer_pool_size = 512Minnodb_data_file_path = ibdata1:256M:autoextendinnodb_file_io_threads = 4innodb_thread_concurrency = 8innodb_flush_log_at_trx_commit = 2innodb_log_buffer_size = 16Minnodb_log_file_size = 128Minnodb_log_files_in_group = 3innodb_max_dirty_pages_pct = 90innodb_lock_wait_timeout = 120innodb_file_per_table = 0#log-slow-queries = /data0/mysql/3306/slow.log#long_query_time = 10[mysqldump]quickmax_allowed_packet = 32MD,Management of MySQL database to create shell script:Enter the following (where the user name admin and the password 12345678 The next step will be tocreate):#!/bin/sh
  • mysql_port=3306mysql_username=”admin”mysql_password=”12345678″function_start_mysql(){ printf “Starting MySQL…n” /bin/sh /usr/local/webserver/mysql/bin/mysqld_safe –defaults-file=/data0/mysql/${mysql_port}/my.cnf2>&1 > /dev/null &}function_stop_mysql(){ printf “Stoping MySQL…n” /usr/local/webserver/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S/tmp/mysql.sock shutdown}function_restart_mysql(){ printf “Restarting MySQL…n” function_stop_mysql sleep 5 function_start_mysql}function_kill_mysql(){ kill -9 $(ps -ef | grep ‘bin/mysqld_safe’ | grep ${mysql_port} | awk ‘{printf $2}’) kill -9 $(ps -ef | grep ‘libexec/mysqld’ | grep ${mysql_port} | awk ‘{printf $2}’)}if [ "$1" = "start" ]; then function_start_mysqlelif [ "$1" = "stop" ]; then function_stop_mysqlelif [ "$1" = "restart" ]; thenfunction_restart_mysqlelif [ "$1" = "kill" ]; thenfunction_kill_mysqlelse printf “Usage: /data0/mysql/${mysql_port}/mysql {start|stop|restart|kill}n”fiE,Given shell script executable permissions:chmod +x /data0/mysql/3306/mysqlF,Start MySQL:/data0/mysql/3306/mysql start
  • G,MySQL command line log management server (direct carriage return when prompted for apassword):/usr/local/webserver/mysql/bin/mysql -u root -p -S /tmp/mysql.sockH,Enter the following SQL statement, create a user with root privileges (admin) and password(12345678):GRANT ALL PRIVILEGES ON *.* TO ‘admin’@localhost’ IDENTIFIED BY ’12345678′;GRANT ALL PRIVILEGES ON *.* TO ‘admin’@’127.0.0.1′ IDENTIFIED BY ’12345678′;3, compiler installed PHP (FastCGI)tar zxvf php-5.2.14.tar.gzgzip -cd php-5.2.14-fpm-0.5.14.diff.gz | patch -d php-5.2.14 -p1cd php-5.2.14/./configure –prefix=/usr/local/webserver/php –with-config-file-path=/usr/local/webserver/php/etc –with-mysql=/usr/local/webserver/mysql –with-mysqli=/usr/local/webserver/mysql/bin/mysql_config –with-iconv-dir=/usr/local –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir=/usr –enable-xml –disable-rpath –enable-discard-path –enable-safe-mode –enable-bcmath –enable-shmop –enable-sysvsem –enable-inline-optimization –with-curl –with-curlwrappers –enable-mbregex –enable-fastcgi –enable-fpm –enable-force-cgi-redirect –enable-mbstring –with-mcrypt –with-gd –enable-gd-native-ttf –with-openssl –with-mhash –enable-pcntl –enable-sockets –with-ldap –with-ldap-sasl –with-xmlrpc –enable-zip –enable-soapmake ZEND_EXTRA_LIBS=’-liconv’make installcp php.ini-dist /usr/local/webserver/php/etc/php.inicd ../4, compile install PHP5 Extension Moduletar zxvf memcache-2.2.5.tgzcd memcache-2.2.5//usr/local/webserver/php/bin/phpize./configure –with-php-config=/usr/local/webserver/php/bin/php-configmakemake installcd ../tar jxvf eaccelerator-0.9.6.1.tar.bz2cd eaccelerator-0.9.6.1//usr/local/webserver/php/bin/phpize./configure –enable-eaccelerator=shared –with-php-config=/usr/local/webserver/php/bin/php-configmakemake installcd ../
  • tar zxvf PDO_MYSQL-1.0.2.tgzcd PDO_MYSQL-1.0.2//usr/local/webserver/php/bin/phpize./configure –with-php-config=/usr/local/webserver/php/bin/php-config –with-pdo-mysql=/usr/local/webserver/mysqlmakemake installcd ../tar zxvf ImageMagick.tar.gzcd ImageMagick-6.5.1-2/./configuremakemake installcd ../tar zxvf imagick-2.3.0.tgzcd imagick-2.3.0//usr/local/webserver/php/bin/phpize./configure –with-php-config=/usr/local/webserver/php/bin/php-configmakemake installcd ../5, modify the php.ini fileReview: find /usr/local/webserver/php/etc/php.ini the extension_dir = “. /”Amended to read extension_dir = “/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613 /”And after this line add the following lines, then save:extension = “memcache.so”extension = “pdo_mysql.so”extension = “imagick.so”Then find output_buffering = OffRevised to output_buffering = OnLook again; cgi.fix_pathinfo = 0Revised cgi.fix_pathinfo = 0, to prevent the file type error parsing vulnerability Nginx.6, configure eAccelerator accelerated PHP:mkdir -p /usr/local/webserver/eaccelerator_cachevi /usr/local/webserver/php/etc/php.iniSkip to press shift + g key configuration files at the very end, add the following configuration information:[eaccelerator]zend_extension=”/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so”
  • eaccelerator.shm_size=”64″eaccelerator.cache_dir=”/usr/local/webserver/eaccelerator_cache”eaccelerator.enable=”1″eaccelerator.optimizer=”1″eaccelerator.check_mtime=”1″eaccelerator.debug=”0″eaccelerator.filter=”"eaccelerator.shm_max=”0″eaccelerator.shm_ttl=”3600″eaccelerator.shm_prune_period=”3600″eaccelerator.shm_only=”0″eaccelerator.compress=”1″eaccelerator.compress_level=”9″7, create www user and group, as well as for blog.950buy.com and www.950buy.com two virtualhosts using the directory:/usr/sbin/groupadd www/usr/sbin/useradd -g www wwwmkdir -p /data0/htdocs/blogchmod +w /data0/htdocs/blogchown -R www:www /data0/htdocs/blogmkdir -p /data0/htdocs/wwwchmod +w /data0/htdocs/wwwchown -R www:www /data0/htdocs/www8, create php-fpm configuration file (php-fpm is a fight for the PHP FastCGI patch management,you can change the php.ini configuration without the need for a smooth restart php-cgi):In /usr/local/webserver/php/etc/directory to create php-fpm.conf file:rm -f /usr/local/webserver/php/etc/php-fpm.confvi /usr/local/webserver/php/etc/php-fpm.confEnter the following (if you install Nginx + PHP for debugging, set the following <valuename=”display_errors”> 0 </ value> to <value name=”display_errors”> 1 </ value>, to display PHP errormessage, otherwise, Nginx will report a blank state of 500 error page):<?xml version=”1.0″ ?><configuration> All relative paths in this config are relative to php’s install prefix <section name=”global_options”> Pid file <value name=”pid_file”>/usr/local/webserver/php/logs/php-fpm.pid</value> Error log file <value name=”error_log”>/usr/local/webserver/php/logs/php-fpm.log</value> Log level <value name=”log_level”>notice</value>
  • When this amount of php processes exited with SIGSEGV or SIGBUS … <value name=”emergency_restart_threshold”>10</value> … in a less than this interval of time, a graceful restart will be initiated. Useful to work around accidental curruptions in accelerator’s shared memory. <value name=”emergency_restart_interval”>1m</value> Time limit on waiting child’s reaction on signals from master <value name=”process_control_timeout”>5s</value> Set to ‘no’ to debug fpm <value name=”daemonize”>yes</value></section><workers> <section name=”pool”> Name of pool. Used in logs and stats. <value name=”name”>default</value> Address to accept fastcgi requests on. Valid syntax is ‘ip.ad.re.ss:port’ or just ‘port’ or ‘/path/to/unix/socket’ <value name=”listen_address”>127.0.0.1:9000</value> <value name=”listen_options”> Set listen(2) backlog <value name=”backlog”>-1</value> Set permissions for unix socket, if one used. In Linux read/write permissions must be set in order to allow connections from web server. Many BSD-derrived systems allow connections regardless of permissions. <value name=”owner”></value> <value name=”group”></value> <value name=”mode”>0666</value> </value> Additional php.ini defines, specific to this pool of workers. <value name=”php_defines”> <value name=”sendmail_path”>/usr/sbin/sendmail -t -i</value> <value name=”display_errors”>0</value> </value> Unix user of processes <value name=”user”>www</value> Unix group of processes <value name=”group”>www</value> Process manager settings <value name=”pm”> Sets style of controling worker process count. Valid values are ‘static’ and ‘apache-like’ <value name=”style”>static</value> Sets the limit on the number of simultaneous requests that will be served. Equivalent to Apache MaxClients directive. Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgi
  • Used with any pm_style. <value name=”max_children”>128</value> Settings group for ‘apache-like’ pm style <value name=”apache_like”> Sets the number of server processes created on startup. Used only when ‘apache-like’ pm_style is selected <value name=”StartServers”>20</value> Sets the desired minimum number of idle server processes. Used only when ‘apache-like’ pm_style is selected <value name=”MinSpareServers”>5</value> Sets the desired maximum number of idle server processes. Used only when ‘apache-like’ pm_style is selected <value name=”MaxSpareServers”>35</value> </value> </value> The timeout (in seconds) for serving a single request after which the worker process will beterminated Should be used when ‘max_execution_time’ ini option does not stop script execution for somereason ’0s’ means ‘off’ <value name=”request_terminate_timeout”>0s</value> The timeout (in seconds) for serving of single request after which a php backtrace will be dumped toslow.log file ’0s’ means ‘off’ <value name=”request_slowlog_timeout”>0s</value> The log file for slow requests <value name=”slowlog”>logs/slow.log</value> Set open file desc rlimit <value name=”rlimit_files”>65535</value> Set max core size rlimit <value name=”rlimit_core”>0</value> Chroot to this directory at the start, absolute path <value name=”chroot”></value> Chdir to this directory at the start, absolute path <value name=”chdir”></value> Redirect workers’ stdout and stderr into main error log. If not set, they will be redirected to /dev/null, according to FastCGI specs <value name=”catch_workers_output”>yes</value> How much requests each process should execute before respawn. Useful to work around memory leaks in 3rd party libraries. For endless request processing please specify 0
  • Equivalent to PHP_FCGI_MAX_REQUESTS <value name=”max_requests”>1024</value> Comma separated list of ipv4 addresses of FastCGI clients that allowed to connect. Equivalent to FCGI_WEB_SERVER_ADDRS environment in original php.fcgi (5.2.2+) Makes sense only with AF_INET listening socket. <value name=”allowed_clients”>127.0.0.1</value> Pass environment variables like LD_LIBRARY_PATH All $VARIABLEs are taken from current environment <value name=”environment”> <value name=”HOSTNAME”>$HOSTNAME</value> <value name=”PATH”>/usr/local/bin:/usr/bin:/bin</value> <value name=”TMP”>/tmp</value> <value name=”TMPDIR”>/tmp</value> <value name=”TEMP”>/tmp</value> <value name=”OSTYPE”>$OSTYPE</value> <value name=”MACHTYPE”>$MACHTYPE</value> <value name=”MALLOC_CHECK_”>2</value> </value> </section> </workers></configuration>9, start php-cgi processes, monitor port 9000 of 127.0.0.1, the process number of 128 (if theserver memory is less than 3GB, you can only open 64 process), the user is wwwulimit -SHn 65535/usr/local/webserver/php/sbin/php-fpm startDescription: /usr/local/webserver/php/sbin/php-fpm there are other parameters, including: start | stop |quit | restart | reload | logrotate, modify php.ini does not restart after the php-cgi, re-load theconfiguration file using the reload.Third, install Nginx 0.8.461, install Nginx required pcre library:tar zxvf pcre-8.10.tar.gzcd pcre-8.10/./configuremake && make installcd ../2, install Nginxtar zxvf nginx-0.8.46.tar.gzcd nginx-0.8.46/./configure –user=www –group=www –prefix=/usr/local/webserver/nginx –with-http_stub_status_module–with-http_ssl_module
  • make && make installcd ../3, to create the log directory Nginxmkdir -p /data1/logschmod +w /data1/logschown -R www:www /data1/logs4, create Nginx configuration fileA, In /usr/local/webserver/nginx/conf/ directory to create nginx.conf filerm -f /usr/local/webserver/nginx/conf/nginx.confvi /usr/local/webserver/nginx/conf/nginx.confEnter the following:user www www;worker_processes 8;error_log /data1/logs/nginx_error.log crit;pid /usr/local/webserver/nginx/nginx.pid;#Specifies the value for maximum file descriptors that can be opened by this process.worker_rlimit_nofile 65535;events{ use epoll; worker_connections 65535;}http{ include mime.types; default_type application/octet-stream; #charset utf-8; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 8m; sendfile on; tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k;
  • fastcgi_busy_buffers_size 128k;fastcgi_temp_file_write_size 128k;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;#limit_zone crawler $binary_remote_addr 10m;server{ listen 80; server_name blog.950buy.com; index index.html index.htm index.php; root /data0/htdocs/blog; #limit_conn crawler 20; location ~ .*.(php|php5)?$ { #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fcgi.conf; } location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*.(js|css)?$ { expires 1h; } 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 /data1/logs/access.log access; }server{ listen 80; server_name www.950buy.com;
  • index index.html index.htm index.php; root /data0/htdocs/www; location ~ .*.(php|php5)?$ { #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fcgi.conf; } log_format wwwlogs ‘$remote_addr – $remote_user [$time_local] “$request” ‘ ‘$status $body_bytes_sent “$http_referer” ‘ ‘”$http_user_agent” $http_x_forwarded_for’; access_log /data1/logs/wwwlogs.log wwwlogs; } server { listen 80; server_name status.blog.950buy.com; location / { stub_status on; access_log off; } }}B,In /usr/local/webserver/nginx/conf/ directory to create fcgi.conf file:vi /usr/local/webserver/nginx/conf/fcgi.confEnter the following:fastcgi_param GATEWAY_INTERFACE CGI/1.1;fastcgi_param SERVER_SOFTWARE nginx;fastcgi_param QUERY_STRING $query_string;fastcgi_param REQUEST_METHOD $request_method;fastcgi_param CONTENT_TYPE $content_type;fastcgi_param CONTENT_LENGTH $content_length;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;fastcgi_param SCRIPT_NAME $fastcgi_script_name;fastcgi_param REQUEST_URI $request_uri;fastcgi_param DOCUMENT_URI $document_uri;fastcgi_param DOCUMENT_ROOT $document_root;fastcgi_param SERVER_PROTOCOL $server_protocol;
  • fastcgi_param REMOTE_ADDR $remote_addr;fastcgi_param REMOTE_PORT $remote_port;fastcgi_param SERVER_ADDR $server_addr;fastcgi_param SERVER_PORT $server_port;fastcgi_param SERVER_NAME $server_name;# PHP only, required if PHP was built with –enable-force-cgi-redirectfastcgi_param REDIRECT_STATUS 200;start Nginxulimit -SHn 65535/usr/local/webserver/nginx/sbin/nginxThe configuration at startup Nginx + PHPvi /etc/rc.localInsert:ulimit -SHn 65535/usr/local/webserver/php/sbin/php-fpm start/usr/local/webserver/nginx/sbin/nginxLinux kernel parameters optimizationvi /etc/sysctl.confInsert:# Addnet.ipv4.tcp_max_syn_backlog = 65536net.core.netdev_max_backlog = 32768net.core.somaxconn = 32768net.core.wmem_default = 8388608net.core.rmem_default = 8388608net.core.rmem_max = 16777216net.core.wmem_max = 16777216net.ipv4.tcp_timestamps = 0net.ipv4.tcp_synack_retries = 2net.ipv4.tcp_syn_retries = 2net.ipv4.tcp_tw_recycle = 1#net.ipv4.tcp_tw_len = 1net.ipv4.tcp_tw_reuse = 1net.ipv4.tcp_mem = 94500000 915000000 927000000net.ipv4.tcp_max_orphans = 3276800#net.ipv4.tcp_fin_timeout = 30#net.ipv4.tcp_keepalive_time = 120net.ipv4.ip_local_port_range = 1024 65535The configuration take effect:
  • /sbin/sysctl -pReboot linuxreboot