Deployment time: 2012-07-24 
OS Environment: CentOS 6.1 
nginx:nginx-1.2.2 
php:php5.3.14 
0, install the dependent package 
 
 
  
  Copy Code code as follows: 
 
 
  
 
 
   Yum install openssl-devel pcre-devel zlib-devel libjpeg-devel libpng-devel freetype-devel gcc make 
 
 
  
1. Add www user to execute nginx 
 
 
  
  Copy Code code as follows: 
 
 
  
 
 
   Useradd-m-r-s/sbin/nologin-d/opt/web/www 
 
 
  
2. Create a temporary directory 
 
 
  
  Copy Code code as follows: 
 
 
  
 
  
  
Mkdir-p/var/tmp/nginx/client/ 
  
Mkdir-p/var/tmp/nginx/proxy/ 
  
Mkdir-p/var/tmp/nginx/fcgi/ 
  
 
 
 
  
3, download the latest stable version of Nginx source code 
 
 
  
  Copy Code code as follows: 
 
 
  
 
  
  
cd/usr/local/src/ 
  
wget http://nginx.org/download/nginx-1.2.2.tar.gz 
  
 
 
 
  
4, decompression, compilation, installation 
 
 
  
  Copy Code code as follows: 
 
 
  
 
  
  
Tar vxzf nginx-1.2.2.tar.gz 
  
CD NGINX-1.2.2/ 
  
./configure \ 
  
--prefix=/opt/web/nginx \ 
  
--error-log-path=/var/log/nginx/error.log \ 
  
--pid-path=/var/run/nginx/nginx.pid \ 
  
--lock-path=/var/lock/nginx.lock \ 
  
--USER=WWW \ 
  
--GROUP=WWW \ 
  
--with-http_ssl_module \ 
  
--with-http_stub_status_module \ 
  
--with-http_gzip_static_module \ 
  
--http-log-path=/var/log/nginx/access.log \ 
  
--http-client-body-temp-path=/var/tmp/nginx/client/\ 
  
--http-proxy-temp-path=/var/tmp/nginx/proxy/\ 
  
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/\ 
  
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi/ 
  
Make 
  
Make install 
  
 
 
 
  
5. Configure Nginx 
 
 
  
  Copy Code code as follows: 
 
 
  
 
 
Vim/opt/web/nginx/conf/nginx.conf 
 
# Specify startup User: 
 
User www www. 
 
# Number of processes, nginx authors think one can, according to their own access to modify 
 
Worker_processes 1; 
 
# Set Error log: 
 
#error_log Logs/error.log Notice; 
 
#error_log Logs/error.log Info; 
 
Error_log/var/log/nginx/error.default.log; 
 
Pid/opt/web/nginx/nginx.pid; 
 
Events { 
 
Use Epoll; 
 
Worker_connections 1024; 
 
} 
 
HTTP { 
 
CharSet Utf-8; 
 
Include Mime.types; 
 
Default_type Application/octet-stream; 
 
#log_format Main ' $remote _addr-$remote _user [$time _local] "$request" 
 
# ' $status $body _bytes_sent ' $http _referer ' 
 
# ' $http _user_agent ', ' $http _x_forwarded_for '; 
 
#access_log Logs/access.log Main; 
 
Sendfile on; 
 
Tcp_nopush on; 
 
Tcp_nodelay on; 
 
#keepalive_timeout 0; 
 
Keepalive_timeout 65; 
 
gzip on; 
 
Gzip_min_length 1000; 
 
Gzip_proxied any; 
 
Gzip_types Text/plain text/css Text/xml 
 
Application/x-javascript Application/xml 
 
Application/atom+xml Text/javascript; 
 
server { 
 
Listen 80; 
 
server_name localhost; 
 
CharSet Utf-8; 
 
#access_log Logs/host.access.log Main; 
 
Location/{ 
 
root HTML; 
 
Index index.html index.htm; 
 
} 
 
#error_page 404/404.html; 
 
# REDIRECT Server error pages to the static page/50x.html 
 
# 
 
Error_page 502 503 504/50x.html; 
 
Location =/50x.html { 
 
root HTML; 
 
} 
 
# Proxy The PHP scripts to Apache listening on 127.0.0.1:80 
 
# 
 
#location ~ \.php$ { 
 
# Proxy_pass http://127.0.0.1; 
 
#} 
 
# Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
 
# 
 
Location ~ \.php$ { 
 
root HTML; 
 
Fastcgi_pass 127.0.0.1:9000; 
 
Fastcgi_index index.php; 
 
#fastcgi_param Script_filename/scripts$fastcgi_script_name; 
 
#include fastcgi_params; 
 
Include fastcgi.conf; 
 
} 
 
# Deny access to. htaccess files, if Apache ' s document Root 
 
# concurs with Nginx ' s one 
 
# 
 
Location ~/\.ht { 
 
Deny all; 
 
} 
 
} 
 
# Another virtual host using mix of ip-, name-, and port-based configuration 
 
# 
 
#server { 
 
# Listen 8000; 
 
# Listen somename:8080; 
 
# server_name somename alias Another.alias; 
 
# location/{ 
 
# root HTML; 
 
# index index.html index.htm; 
 
# } 
 
#} 
 
# HTTPS Server 
 
# 
 
#server { 
 
# Listen 443; 
 
# server_name localhost; 
 
# SSL on; 
 
# ssl_certificate Cert.pem; 
 
# Ssl_certificate_key Cert.key; 
 
# ssl_session_timeout 5m; 
 
# ssl_protocols SSLv2 SSLv3 TLSv1; 
 
# ssl_ciphers high:!anull:! MD5; 
 
# ssl_prefer_server_ciphers on; 
 
# location/{ 
 
# root HTML; 
 
# index index.html index.htm; 
 
# } 
 
#} 
 
Proxy_read_timeout 200; 
 
# only retry if there is a communication error, not a timeout 
 
# on the Tornado server (to avoid propagating "queries of death" 
 
# to all Frontends) 
 
Proxy_next_upstream error; 
 
Proxy_set_header X-scheme $scheme; 
 
Proxy_set_header X-real-ip $remote _addr; 
 
Proxy_set_header Host $host; 
 
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for; 
 
# Introduction of Virtual Host files 
 
include/opt/web/nginx/conf/sites/*.conf; 
 
} 
 
 
 
6, the establishment of virtual machine configuration files stored in the directory 
 
 
  
  Copy Code code as follows: 
 
 
  
 
 
   Mkdir/opt/web/nginx/conf/sites 
 
 
  
After this configuration, you need to add a new virtual host directly in the nginx/conf/sites/directory, adding a configuration file can 
For example: Now there are www.jb51.net domain names 
Establish:/opt/web/nginx/conf/sites/www.jb51.net.conf file 
The contents are as follows: 
 
 
  
  Copy Code code as follows: 
 
 
  
 
 
server { 
 
Listen 80; 
 
Client_max_body_size 10M; 
 
#多个域名用空格分割, the first one is the default 
 
server_name www.jb51.net jb51.net; 
 
CharSet UTF-8; 
 
Index index.html index.htm index.php; 
 
# define root directory 
 
Set $root/var/webroot/www.jb51.net/; 
 
# Set the site path 
 
Root $root; 
 
# Prevent Directory browsing 
 
AutoIndex off; 
 
if ($host!= ' www.jb51.net ') { 
 
Rewrite ^/(. *) $ http://www.jb51.net/$1 permanent; 
 
} 
 
# Prevent. htaccess files from being requested 
 
Location ~/\.ht { 
 
Deny all; 
 
} 
 
Error_page 404/404.html; 
 
Index index.html index.htm; 
 
location/uploads/{ 
 
alias/data/webroot/www.jb51.net/uploads/; 
 
} 
 
Try_files $uri @uwsgi; 
 
Location @uwsgi { 
 
# turn over other requests to Uwsgi 
 
Include Uwsgi_params; 
 
Uwsgi_pass Unix:/tmp/360ito_uwsgi.sock; 
 
Proxy_set_header X-real-ip $remote _addr; 
 
Proxy_set_header Host $host; 
 
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for; 
 
#proxy_pass http://localhost:5000; 
 
} 
 
# transfer PHP type request to fastcgi 
 
Location ~ \.php$ { 
 
root HTML; 
 
Fastcgi_pass 127.0.0.1:9000; 
 
Fastcgi_index index.php; 
 
Include fastcgi.conf; 
 
} 
 
# Access log: 
 
Access_log/var/log/nginx/access.www.jb51.net.log; 
 
# load. htaccess rewrite file, note that the variable path is not supported here 
 
# cannot be written as include $root/www.jb51.net/.htaccess; 
 
# include/var/webroot/www.jb51.net/.htaccess; 
 
# Open the domain name jump, then when the access error, the other domain name will automatically jump to www.jb51.net 
 
# Note, here I say, only when the access error, will jump, so, here does not achieve 301 redirect! 
 
Server_name_in_redirect on; 
 
} 
 
 
 
7, install the latest version of PHP (PHP5.3.14) 
 
 
  
  Copy Code code as follows: 
 
 
  
 
  
  
cd/usr/local/src/ 
  
wget Http://cn.php.net/get/php-5.3.14.tar.bz2/from/this/mirror 
  
Tar xjvf php-5.3.14.tar.bz2 
  
CD php-5.3.14 
  
 
 
 
  
Perform: 
 
 
  
  Copy Code code as follows: 
 
 
  
 
If the error, may be your autoconf is not version 2.13, PHP5.3. Series of bugs, you need to install the version of Autoconf 2.13: 
 
 
  
  Copy Code code as follows: 
 
 
  
 
  
  
CentOS: # yum Install autoconf213 
  
Debian: # apt-get Install autoconf2.13 
  
 
 
 
  
Setting environment variables 
 
 
  
  Copy Code code as follows: 
 
 
  
 
  
  
# CentOS: 
  
Export php_autoconf= "/usr/bin/autoconf-2.13" 
  
# Debian: 
  
Export php_autoconf= "/usr/bin/autoconf2.13" 
  
 
 
 
  
Run again:./buildconf--force, appears buildconf:autoconf version 2.13 (OK) 
, it indicates success. 
Compiling and installing PHP 
 
 
  
  Copy Code code as follows: 
 
 
  
 
  
  
./configure \ 
  
--prefix=/opt/web/php \ 
  
--WITH-CONFIG-FILE-PATH=/OPT/WEB/PHP/ETC \ 
  
--WITH-CONFIG-FILE-SCAN-DIR=/OPT/WEB/PHP/ETC/CONF.D \ 
  
--ENABLE-FPM \ 
  
--WITH-FPM-USER=WWW \ 
  
--WITH-FPM-GROUP=WWW \ 
  
--with-mysql=/opt/db/percona-server-5.5.14-rel20.5 \ 
  
--with-mysqli=/opt/db/percona-server-5.5.14-rel20.5/bin/mysql_config \ 
  
--with-iconv-dir \ 
  
--with-freetype-dir \ 
  
--with-jpeg-dir \ 
  
--with-png-dir \ 
  
--with-zlib \ 
  
--with-libxml-dir \ 
  
--enable-xml \ 
  
--enable-mbstring \ 
  
--WITH-GD \ 
  
--ENABLE-GD-NATIVE-TTF \ 
  
--WITH-OPENSSL \ 
  
--enable-inline-optimization 
  
Make && make install 
  
CP Php.ini-production/opt/web/php/etc/php.ini 
  
Cd/opt/web/php/etc 
  
CP Php-fpm.conf.default php-fpm.conf 
  
 
 
 
  
Modify php-fpm.conf enable the following lines, that is, remove the preceding semicolon (;) 
 
 
  
  Copy Code code as follows: 
 
 
  
 
  
  
PID = Run/php-fpm.pid 
  
Error_log = Log/php-fpm.log 
  
Log_level = Notice 
  
Listen = 127.0.0.1:9000 
  
Listen.allowed_clients = 127.0.0.1 
  
Listen.owner = www 
  
Listen.group = www 
  
Listen.mode = 0666 
  
user = www 
  
Group = www 
  
PM = dynamic 
  
Pm.max_children = 50 
  
Pm.start_servers = 5 
  
Pm.min_spare_servers = 5 
  
Pm.max_spare_servers = 35 
  
Pm.max_requests = 500 
  
Env[hostname] = $HOSTNAME 
  
Env[path] =/usr/local/bin:/usr/bin:/bin 
  
ENV[TMP] =/tmp 
  
ENV[TMPDIR] =/tmp 
  
ENV[TEMP] =/tmp 
  
 
 
 
  
8, start PHP-FPM 
 
 
  
  Copy Code code as follows: 
 
 
  
 
 
   /opt/web/php/sbin/php-fpm 
 
 
  
Start Nginx 
 
 
  
  Copy Code code as follows: 
 
 
  
 
 
   /opt/web/nginx/sbin/nginx 
 
 
  
9. Test 
 
 
  
  Copy Code code as follows: 
 
 
  
 
 
   vim/var/webroot/www.jb51.net/tz.php 
 
 
  
Enter and save 
 
 
  
  Copy Code code as follows: 
 
 
  
 
10, in the browser address bar input: http://php.jb51.net/tz.php 
Successful, you can see the phpinfo () output information