Deployment time:
OS environment: CentOS 6.1
Nginx: nginx-1.2.2
PHP: PHP5.3.14
0. Install the dependency package
Copy codeThe Code is as follows: yum install openssl-devel pcre-devel zlib-devel libjpeg-devel libpng-devel freetype-devel gcc make
1. Add a www user to execute nginxCopy codeThe Code is as follows: useradd-M-r-s/sbin/nologin-d/opt/web/www
2. Create a temporary directoryCopy codeThe Code is 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 codeCopy codeThe Code is as follows: cd/usr/local/src/
Wget http://nginx.org/download/nginx-1.2.2.tar.gz
4. decompress, compile, and installCopy codeThe Code is 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. 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 nginxCopy codeThe Code is as follows: vim/opt/web/nginx/conf/nginx. conf
# Specify the user to start:
User www;
# The number of processes, which the nginx author thinks can be modified based on their own traffic volume
Worker_processes 1;
# Set error logs:
# Error_log logs/error. log notice;
# Error_log logs/error. log info;
Error_log/var/log/nginx/error. default. log;
Pid/opt/web/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 500 502 503 x.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 Fig: 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 5 m;
# 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 was 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;
# Introduce VM files
Include/opt/web/nginx/conf/sites/*. conf;
}
6. Create a directory for storing virtual machine configuration filesCopy codeThe Code is as follows: mkdir/opt/web/nginx/conf/sites
After this configuration, you need to add a new virtual host directly under the nginx/conf/sites/directory and add the configuration file.
Example: www.jb51.net Domain Name
Create the/opt/web/nginx/conf/sites/www.jb51.net. conf file.
The content is as follows:Copy codeThe Code is as follows: server {
Listen 80;
Client_max_body_size 10 M;
# Separate multiple domain names with spaces. The first one is the default one.
Server_name www.jb51.net jb51.net;
Charset UTF-8;
Index index.html index.htm index. php;
# Define the 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 {
# Transfer 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 requests 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 the. 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;
# When Domain Name Redirection is enabled, when an access error occurs, other domain names will automatically jump to www.jb51.net
# Note: Here I am talking about the jump only when an access error occurs. Therefore, 301 redirection cannot be implemented here!
Server_name_in_redirect on;
}
7. Install the latest PHP version (PHP5.3.14)Copy codeThe Code is 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
Run:Copy codeThe Code is as follows:./buildconf -- force
If an error is reported, it may be that your autoconf version is not 2.13. For PHP5.3. For a series bug, you must install the autoconf version 2.13:Copy codeThe Code is as follows: CentOS: # yum install autoconf213
Debian: # apt-get install autoconf2.13
Set Environment VariablesCopy codeThe Code is as follows: # CentOS:
Export PHP_AUTOCONF = "/usr/bin/autoconf-2.13"
# Debian:
Export PHP_AUTOCONF = "/usr/bin/autoconf2.13"
Run:./buildconf -- force again, And buildconf: autoconf version 2.13 (OK) appears)
.
Compile and install PHPCopy codeThe Code is 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 the php-fpm.conf to enable the following lines, removing the semicolon (;) above (;)Copy codeThe Code is 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-fpmCopy codeThe Code is as follows:/opt/web/php/sbin/php-fpm
Start nginxCopy codeThe Code is as follows:/opt/web/nginx/sbin/nginx
9. Test it.Copy codeThe Code is as follows: vim/var/webroot/www.jb51.net/tz.php
Input and saveCopy codeThe Code is as follows: <? PHP
Phpinfo ();
?>
10, in the browser address bar input: http://php.jb51.net/tz.php
If it succeeds, you can see the output information of phpinfo ().