Ubuntu10.04 with nginx + php-fpm mode

Source: Internet
Author: User
Ubuntu10.04 Configure nginx + php-fpm mode for ppa to install php-fpm installation toolkit $ sudoapt-getinstallpython-software-properties add ppa Source $ sudoadd-apt-repositoryppa: yolaphp5 install php5-fpmsudoapt-get ubuntu10.04 Configure nginx + php-fpm mode
Install php-fpm using ppa


Installation Kit

$ sudo apt-get install python-software-properties 

Add ppa source

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

Install php5-fpm

sudo  apt-get  updatesudo  apt-get install  php5-fpm

Install other necessary software

sudo   apt-get   install   nginx

Configure php-fpm


The php-fpm parser is in the C/S structure, and its configuration file is located:

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

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

Generally, there are no strict configuration requirements, or I have not specifically studied the significance of each configuration parameter.

I used the tcp mode to connect to the fastcgi process, so I modified the address and port of the tcp listener and the name of the monitoring Directory. I will not explain it in detail here, you can refer to the official documentation for configuration based on your needs.


Restart php5-fpm



Configure nginx


Preface

Nginx itself does not parse the php language, which is different from apache (apache has php parsing in the mod_php module ). nginx is through fastcgi Client php requests to the background php5-fpm process manager, php5-fpm has the ability to parse php, specific can refer to my previous blog mod_php mod_fastcgi comparison


Nginx main configuration file

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

User www-data; # enable the cpu multi-core function worker_processes 2; worker_cpu_affinity 01 10; # specify the maximum number of file descriptors that can be opened by the nginx process worker_rlimit_nofile 65535; pid/var/run/nginx. pid; events {# use epoll I/O model of epoll; # number of concurrent connections of work order processes. total number of concurrent connections = worker_connections * worker_processesworker_connections 2048; # multi_accept call accept () after Nginx receives a new connection notification to accept as many connections as possible multi_accept on;} http {include/etc/nginx/mime. types; default_type application/octet-stream; charset UTF-8; bytes 128; client_header_buffer_size 2 k; Bytes 4 4 k; # client_max_body_size 8 m; # $ remote_addr: record IP address; $ remote_user: record remote client user name; $ request: request url and http protocol; $ status: used to record request status; $ body_bytes_sent: used to record the size of the content sent to the client file body; $ http_referer: Jump link; $ http_x_forwarded_for: the customer's real IP address log_format main' $ server_name $ remote_addr $ remote_user [$ time_local] "$ request" ''$ status $ response" $ 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 timeout value: keepalive_timeout 60; open_file_cache max = 204800 inactive = 20 s; timeout 1; open_file_cache_valid 30 s; tcp_nodelay on; gzip on; include/etc/nginx/conf. d /*. conf ;}
Log formats are separated by non-printable characters. ctrl + v & ctrl +


Nginx virtual host configuration file

Upstream haolianxi_php {server 127.0.0.1: 9444;} server {listen192.168.1.20.: 7777; access_log/var/log/nginx/haolianxi. access. log main; error_log/var/log/nginx/haolianxi. error. log; # General match 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 ;}# regular expression matching # 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 16 8 k; gzip_types text/plain text/css application/x-javascript text/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 "MSIE [1-6]. (?!. * SV1) "; # Set a vary header so downstream proxies don't send cached gzipped content to IE6 gzip_vary on; ##/ Compression}

Note:

Modify the parameter settings in include/etc/nginx/fastcgi_params as follows:

fastcgi_param   SCRIPT_NAME             $document_root$fastcgi_script_name;

Because the script name does not add $ document_root, the php5-fpm cannot find the absolute path of the php script to be executed


Restart nginx

sudo  /etc/init.d/nginx  restart

Test the fastcgi_finish_request () function.

 

Note:

Fastcgi_finish_request () can be used to close the connection with the client in advance and return the data to the client. However, the branch business logic after the function continues to run in the background!


Php5-fpm logs split by day script

#! /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 cutting for category in $ {category_array [*]} doif [-e $ php5_fpm_logs_path/php5-fpm. $ category. log] thenmv $ php5_fpm_logs_path/php5-fpm. $ category. log \ $ php5_fpm_logs_path/php5-fpm. $ category. $ postfixfidone #4. 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 $2} ''# USR1: Reopen log files, refresh the nginx log file kill-USR1 $ php5fpm_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.