b.在node6上安装nginx作为静态内容处理
编译安装nginx
# tar xfnginx-1.6.1.tar.gz -C /usr/local/
首先添加用户nginx,实现以之运行nginx服务进程:
# groupadd -rnginx
# useradd -r -gnginx nginx
安装一些依赖的包
# yum install -ygcc gcc-c++ pcre-devel openssl-devel
接着开始编译和安装:
# ./configure--prefix=/usr/local/nginx --error-log-path=/var/log/nginx/error.log--http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid--lock-path=/var/lock/nginx.lock --user=nginx --group=nginx--with-http_ssl_module --with-http_flv_module --with-http_stub_status_module--with-http_gzip_static_module--http-client-body-temp-path=/usr/local/nginx/client--http-proxy-temp-path=/usr/local/nginx/proxy --with-pcre
# make &&make install
提供启动脚本,/etc/rc.d/init.d/nginx
#!/bin/sh
#
# nginx - thisscript starts and stops the nginx daemon
#
# chkconfig: - 85 15
#description: Nginx is an HTTP(S) server,HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname:nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source functionlibrary.
./etc/rc.d/init.d/functions
# Sourcenetworking configuration.
./etc/sysconfig/network
# Check thatnetworking is up.
["$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename$nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f/etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`nginx -V 2>&1 | grep"configure arguments:" | sed ‘s/[^*]*--user=\([^ ]*\).*/\1/g‘ -`
options=`$nginx -V 2>&1 | grep‘configure arguments:‘`
for opt in $options; do
if [ `echo $opt | grep ‘.*-temp-path‘`]; then
value=`echo $opt | cut -d"=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating"$value
mkdir -p $value && chown-R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f$NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch$lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f$lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case"$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0{start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
而后为此脚本赋予执行权限:
# chmod +x/etc/rc.d/init.d/nginx
添加至服务管理列表,并让其开机自动启动:
# chkconfig --addnginx
# chkconfig nginxon
而后就可以启动服务并测试了:
# service nginxstart
# ss -tnlp | grep80
上传文件测试访问
访问中文文件名乱码问题
解决办法:http://www.apelearn.com/bbs/thread-7630-1-1.html
centos上直接用yum安装:
yum install -y convmv
假如,转码命令为:
convmv -f 源编码 -t 目标编码 --notest filename
我想,大多数情况下,因为这个文件名是乱码,所以没有办法去表示它,只好使用通配:
convmv -f GBK -t UTF-8 --notest *.txt
此时浏览器内容显示的是乱码,查看一下发现浏览器的显示格式为utf-8,改一下GBK的,这样就显示正常了
c.在node5上安装nginx+php
编译安装nginx
# tar xfnginx-1.6.1.tar.gz -C /usr/local/
首先添加用户nginx,实现以之运行nginx服务进程:
# groupadd -rnginx
# useradd -r -gnginx nginx
安装一些依赖的包
# yum install -ygcc gcc-c++ pcre-devel openssl-devel
接着开始编译和安装:
# ./configure--prefix=/usr/local/nginx --error-log-path=/var/log/nginx/error.log--http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid--lock-path=/var/lock/nginx.lock --user=nginx --group=nginx--with-http_ssl_module --with-http_flv_module --with-http_stub_status_module--with-http_gzip_static_module--http-client-body-temp-path=/usr/local/nginx/client--http-proxy-temp-path=/usr/local/nginx/proxy --with-pcre
# make &&make install
提供启动脚本,/etc/rc.d/init.d/nginx
#!/bin/sh
#
# nginx - this scriptstarts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
./etc/rc.d/init.d/functions
# Source networkingconfiguration.
. /etc/sysconfig/network
# Check that networking isup.
[ "$NETWORKING"= "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`nginx -V 2>&1 | grep"configure arguments:" | sed ‘s/[^*]*--user=\([^ ]*\).*/\1/g‘ -`
options=`$nginx -V 2>&1 | grep‘configure arguments:‘`
for opt in $options; do
if [ `echo $opt | grep ‘.*-temp-path‘`]; then
value=`echo $opt | cut -d"=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating"$value
mkdir -p $value && chown-R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch$lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f$lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0{start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
而后为此脚本赋予执行权限:
# chmod +x/etc/rc.d/init.d/nginx
添加至服务管理列表,并让其开机自动启动:
# chkconfig --addnginx
# chkconfig nginxon
而后就可以启动服务并测试了:
# service nginxstart
# ss -tnlp | grep80
安装php,MySQL独立部署为一台机器
解压
# tar xfphp-5.4.26.tar.bz2 -C /usr/local/
安装依赖的包:
#yuminstall -y libxml2-devel bzip2-devel libmcrypt-devel libcurl-devel
说明:
这里为了支持apache的worker或event这两个MPM,编译时使用了--enable-maintainer-zts选项。
如果使用PHP5.3以上版本,为了链接MySQL数据库,可以指定mysqlnd,这样在本机就不需要先安装MySQL或MySQL开发包了。mysqlnd从php 5.3开始可用,可以编译时绑定到它(而不用和具体的MySQL客户端库绑定形成依赖),但从PHP 5.4开始它就是默认设置了。
# ./configure --with-mysql=mysqlnd--with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd
编译安装libmcrypt
# tar zxvflibmcrypt-2.5.8.tar.gz
# cdlibmcrypt-2.5.8
# ./configure
# make &&make install
配置
# ./configure--prefix=/usr/local/php --with-mysql=mysqlnd --with-openssl --enable-fpm--with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --enable-mbstring--with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir--with-libxml-dir=/usr --enable-xml --with-mhash --with-mcrypt --with-config-file-path=/etc/php --with-config-file-scan-dir=/etc/php--with-bz2 --with-curl
编译和安装
#make &&make install
启动fastcgi:
# cp/usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# cpphp.ini-production /etc/php.ini
# cpsapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
# chmod +x/etc/rc.d/init.d/php-fpm
# chkconfig --addphp-fpm
# vim/usr/local/php/etc/php-fpm.conf
启用如下选项:
pm.max_children =50
pm.start_servers =5
pm.min_spare_servers= 2
pm.max_spare_servers= 8
pid =/var/run/php-fpm.pid
把/usr/local/nginx/conf/fastcgi_params中的内容替换为
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;
启用nginx配置文件中
location / {
root html;
index index.php index.htmlindex.htm; 需要加上index.php
}
.....
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;
}
# cat /usr/local/nginx/html/index.php
<?php
phpinfo();
?>
#service php-fpmstart
测试访问