ubuntu
安装相关的软件包
sudo apt-get install libpcre3 libpcre3-dev build-essential libssl-dev
下载nginx及nginx_upstream_hash补丁包
wget http://nginx.org/download/nginx-1.2.8.tar.gz
wget http://wiki.nginx.org/p_w_picpaths/1/11/Nginx_upstream_hash-0.3.1.tar.gz
解压及打补丁
tar zxvf nginx-1.2.8.tar.gz
tar zxvf Nginx_upstream_hash-0.3.1.tar.gz
cd nginx-1.2.8/
patch -p0 < ../nginx_upstream_hash-0.3.1/nginx.patch
配置
./configure \
--prefix=/usr \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=www-data \
--group=www-data \
--with-http_gzip_static_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_ssl_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/ \
--add-module=../nginx_upstream_hash-0.3.1/
编译与安装
make && sudo make install
创建/var/tmp/nginx/client/
sudo mkdir -p /var/tmp/nginx/client/
vim /etc/init.d/nginx
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/nginx
NAME=nginx
DESC=nginx
test -x $DAEMON || exit 0
# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
. /etc/default/nginx
fi
set -e
. /lib/lsb/init-functions
test_nginx_config() {
if nginx -t $DAEMON_OPTS
then
return 0
else
return $?
fi
}
case "$1" in
start)
echo -n "Starting $DESC: "
test_nginx_config
start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
--exec $DAEMON -- $DAEMON_OPTS || true
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
--exec $DAEMON || true
echo "$NAME."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
start-stop-daemon --stop --quiet --pidfile \
/var/run/$NAME.pid --exec $DAEMON || true
sleep 1
test_nginx_config
start-stop-daemon --start --quiet --pidfile \
/var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC configuration: "
test_nginx_config
start-stop-daemon --stop --signal HUP --quiet --pidfile /var/run/$NAME.pid \
--exec $DAEMON || true
echo "$NAME."
;;
configtest)
echo -n "Testing $DESC configuration: "
if test_nginx_config
then
echo "$NAME."
else
exit $?
fi
;;
status)
status_of_proc -p /var/run/$NAME.pid "$DAEMON" nginx && exit 0 || exit $?
;;
*)
echo "Usage: $NAME {start|stop|restart|reload|force-reload|status|configtest}" >&2
exit 1
;;
esac
exit 0
添加执行权限
chmod
设置开机启动
sudo update-rc.d nginx defaults
安装php+mysql
http://wiki.ubuntu.org.cn/Nginx官方文档详细安装步骤
Redhat/centOS
yum install pcre pcre-devel openssl-devel openssl
yum groupinstall "Development Tools"(类似ubuntu的build-essential)
其他的同ubuntu步骤一样
chkconfig nginx on
安装start-stop-daemon支持/etc/init.d/nginx脚本
wget http://developer.axis.com/download/distribution/apps-sys-utils-start-stop-daemon-IR1_9_18-2.tar.gz
tar-xzf apps-sys-utils-start-stop-daemon-IR1_9_18-2.tar.gz
cd ~/src/apps/sys-utils/start-stop-daemon-IR1_9_18-2
gcc start-stop-daemon.c -o start-stop-daemon
cp start-stop-daemon /usr/local/sbin/
chmod +x /usr/local/sbin/start-stop-daemon
php官网下载最新稳定版
http://cn2.php.net/get/php-5.4.15.tar.gz/from/a/mirror
安装一些相关软件包
yum install libxml2-devel libcurl-devel
解压与配置
tar xvf php-5.4.15.tar.gz
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --enable-sockets --enable-zip
编译与安装
make && make install
编译php-fpm配置文件
cp php-fpm.conf.default php-fpm.conf
启动php-fpm
/usr/local/php/sbin/php-fpm
编译配置nginx.conf或者其他需要配置php支持的站点中
在需要的站点中添加以下区块
location \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
/etc/init.d/nginx configtest
/etc/init.d/nginx reload
elinks http://www.test.com