ubuntu10.04 with Nginx + php-fpm mode

Source: Internet
Author: User
ubuntu10.04 configuration Nginx + php-fpm mode

PPA installation PHP-FPM


Installation Kit


Add PPA Source

$  sudo add-apt-repository ppa:yola/php5

Installing PHP5-FPM

sudo  apt-get  updatesudo  apt-get Install  php5-fpm

Other necessary Software Installation connection

sudo   apt-get   install   nginx

Configure PHP-FPM


The PHP-FPM parser is the C/s structure, and its configuration file is located at:

(1)/etc/php5/fpm/php-fpm.conf

(2)/etc/php5/fpm/pool.d/

Generally there is no strict configuration requirements, or this piece I have not specifically studied the meaning of each configuration parameter

I used TCP mode to connect with the fastcgi process, so I modified the TCP listening address and port, modified the name of the monitoring directory, here do not do a detailed explanation, you can refer to the official documents according to their own needs to configure


Restart PHP5-FPM



Configure Nginx


Objective

Nginx itself does not parse the PHP language, this is different from Apache (Apache has in the band of the mod_php module PHP parsing). Nginx is the PHP5-FPM process manager that passes the client's PHP request to the background through fastcgi. PHP5-FPM has the function of parsing PHP, specifically can refer to my previous blog mod_php contrast mod_fastcgi


Nginx's main configuration file

File location:/etc/nginx/nginx.conf, my configuration parameters are as follows:

User Www-data, #主动开启cpu多核功能worker_processes 2;worker_cpu_affinity; #指定nginx进程可以打开的最大文件描述符数量worker_rlimit_ Nofile 65535;pid/var/run/nginx.pid;events {#使用epoll的I/O model use Epoll; #工作单进程的并发连接数, total concurrent connections = Worker_connections * Worker _processesworker_connections 2048; #multi_accept在Nginx接到一个新连接通知后调用accept () to accept as many connections as possible multi_accept on;} HTTP {include/etc/nginx/mime.types;default_type Application/octet-stream;charset utf-8;server_names_hash_bucket_s ize 128;client_header_buffer_size 2k;large_client_header_buffers 4 4k; #通过nginx上传文件的大小client_max_body_size 8m;#$ REMOTE_ADDR: Record IP address, $remote _user: Record remote client user name, $request: requested URL and HTTP protocol; $status: used to log request status; $body _bytes_sent: Used to record the size of the principal content sent to the client file; $http _referer: Jump link; $http _x_forwarded_for: Customer's real IP address log_format main ' $server _name$remote_addr$ remote_user[$time _local] "$request" "$status $body_bytes_sent" $http _referer "" "$ Http_user_agent "" $http _x_forwarded_for "'; Access_log/var/log/nginx/access.log main;error_log/var/log/ngInx/error.log;sendfile On;tcp_nopush on; #keepalive的超时时间keepalive_timeout 60;open_file_cache max=204800 Inactiv    E=20s;open_file_cache_min_uses 1;open_file_cache_valid 30s;    Tcp_nodelay on;    gzip on; include/etc/nginx/conf.d/*.conf;}
The log format is delimited with non-printable symbols, CTRL + V && CTRL + A


Nginx Virtual Host configuration file

Upstream haolianxi_php {server 127.0.0.1:9444;} server {Listen192.168.1.137:7777;access_log/var/log/nginx/haolianxi/haolianxi.access.log main;error_log/var/log/ Nginx/haolianxi/haolianxi.error.log; #通用匹配location/{root/srv/www/php/;autoindex on;autoindex_exact_size off; Autoindex_localtime on;access_log/var/log/nginx/haolianxi/location.default.access.logmain;error_log/var/log/ Nginx/haolianxi/location.default.error.log;allow 192.168.1.0/24;deny All;} #正则表达式匹配 #proxy the PHP scripts to Php-fpmlocation ~ \.php$ {root/srv/www/php/;include/etc/nginx/fastcgi_params;fastcgi _passhaolianxi_php;# the upstream determined abovefastcgi_indexindex.php;} #php-fpm Status Monitorlocation =/phpfpm_status {fastcgi_pass 127.0.0.1:9444;fastcgi_index index.php;include/etc/ Nginx/fastcgi_params;allow192.168.1.127;allow127.0.0.1;deny all;}    # # compression# src:http://www.ruby-forum.com/topic/141251# Src:http://wiki.brightbox.co.uk/docs:nginx gzip on;    Gzip_http_version 1.0;    Gzip_comp_level 2; Gzip_proxiEd any;    Gzip_min_length 1100;    Gzip_buffers 8k;        Gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript; # Some version of IE 6 don ' t handle compression well on Some mime-types, so just disable for them gzip_disable "MSI E [1-6]. (?!.        *SV1) ";    # Set a vary header so downstream proxies don ' t send cached gzipped content to IE6 gzip_vary on; # #/compression}

Attention:

A parameter setting in Include/etc/nginx/fastcgi_params needs to be modified as follows:

Fastcgi_param   script_name             $document _root$fastcgi_script_name;

Because the name of the script does not add $document_root,php5-fpm, the absolute path of the PHP script that needs to be executed cannot be found.


Re-start Nginx

sudo  /etc/init.d/nginx  restart

Test Fastcgi_finish_request () function

 
  

Description

In the most white words, fastcgi_finish_request () can close the connection with the client in advance and return the data that needs to be returned to the client, but the branch business logic behind the function continues to run in the background!


PHP5-FPM log Split script by day

#!/bin/bash-#1. PHP5-FPM Log storage path php5_fpm_logs_path= "/var/log/php5-fpm/" category_array= ("Access" "Error") #2. PHP5-FPM log name suffix postfix= ' date-d '-1 days ' +%y%m%d ' ". Log" #3. PHP5-FPM log cut for category in ${category_array[*]}doif [-e $php 5 _fpm_logs_path/php5-fpm. $category. Log]thenmv $php 5_fpm_logs_path/php5-fpm. $category. log \ $php 5_fpm_logs_path/ php5-fpm. $category. $postfixfidone # # # Find the PHP5-FPM process number to generate a new log file php5fpm_pid= ' Ps-aux |grep-e ' php-fpm:master process ' | Grep-v ' grep ' |awk ' {print $} ' #USR1: Reopen log files, flush nginx logfile KILL-USR1 $php 5fpm_pid



  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.