1:选定源码目录
选定目录 /usr/local/
2:安装PCRE库
cd /usr/local/
[root@ser6-70 local]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz
--2015-08-10 18:14:53-- ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz
=> “pcre-8.36.tar.gz”
Resolving ftp.csx.cam.ac.uk... 131.111.8.115
Connecting to ftp.csx.cam.ac.uk|131.111.8.115|:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done. ==> PWD ... done.
==> TYPE I ... done. ==> CWD (1) /pub/software/programming/pcre ... done.
==> SIZE pcre-8.36.tar.gz ... 2009464
==> PASV ... done. ==> RETR pcre-8.36.tar.gz ... done.
Length: 2009464 (1.9M) (unauthoritative)
100%[===================================================================================================================>] 2,009,464 437K/s in 4.9s
2015-08-10 18:15:20 (401 KB/s) - “pcre-8.36.tar.gz” saved [2009464]
tar -xvf pcre-8.36.tar.gz
cd pcre-8.36
./configure
make
make install
假如./configure报错:configure: error: You need a C++ compiler for C++ support
需要yum install -y gcc gcc-c++
3:安装zlib库
cd /usr/local/
[root@ser6-70 local]# wget http://zlib.net/zlib-1.2.8.tar.gz
--2015-08-10 18:19:44-- http://zlib.net/zlib-1.2.8.tar.gz
Resolving zlib.net... 69.73.132.10
Connecting to zlib.net|69.73.132.10|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 571091 (558K) [application/x-gzip]
Saving to: “zlib-1.2.8.tar.gz”
100%[===================================================================================================================>] 571,091 12.8K/s in 25s
2015-08-10 18:20:11 (22.1 KB/s) - “zlib-1.2.8.tar.gz” saved [571091/571091]
tar -zxvf zlib-1.2.8.tar.gz cd zlib-1.2.8
cd zlib-1.2.8
./configure
make
make install
4:安装ssl
cd /usr/local/
[root@ser6-70 ~]# wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
--2015-08-11 09:25:50-- http://www.openssl.org/source/openssl-1.0.1c.tar.gz
Resolving www.openssl.org... 194.97.150.234, 2001:608:c00:180::1:ea
Connecting to www.openssl.org|194.97.150.234|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4457113 (4.2M) [application/x-gzip]
Saving to: “openssl-1.0.1c.tar.gz”
5% [=====> ] 247,230 8.09K/s eta 7m 33s
5% [=====> ] 251,574 7.33K/s eta 7m 33s
5% [=====> ] 258,814 8.50K/s eta 7m 32s
5% [=====> ] 258,814 7.85K/s eta 7m 32s
5% [=====> ] 266,054 8.30K/s eta 7m 45s
6% [======> ] 283,430 8.95K/s eta 7m 42s
100%[===================================================================================================================>] 4,457,113 5.58K/s in 10m 44s
2015-08-11 09:36:35 (6.76 KB/s) - “openssl-1.0.1c.tar.gz” saved [4457113/4457113]
tar -zxvf openssl-1.0.1c.tar.gz
cd openssl-1.0.1c
./config
make
make install
假如make install的时候报错:
POD document had syntax errors at /usr/bin/pod2man line 69.
make: *** [install_docs] Error 1
解决方法:
执行:
rm -f /usr/bin/pod2man
重新编译安装即可。
5:安装nginx
Nginx 一般有两个版本,分别是稳定版和开发版,您可以根据您的目的来选择这两个版本的其中一个,下面是把 Nginx 安装到 /usr/local/nginx 目录下的详细步骤:
cd /usr/local/
[root@ser6-70 ~]# wget http://nginx.org/download/nginx-1.2.8.tar.gz
--2015-08-11 09:54:31-- http://nginx.org/download/nginx-1.2.8.tar.gz
Resolving nginx.org... 206.251.255.63, 2606:7100:1:69::3f
Connecting to nginx.org|206.251.255.63|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 730589 (713K) [application/octet-stream]
Saving to: “nginx-1.2.8.tar.gz”
100%[===================================================================================================================>] 730,589 23.7K/s in 39s
2015-08-11 09:55:11 (18.4 KB/s) - “nginx-1.2.8.tar.gz” saved [730589/730589]
tar -zxvf nginx-1.2.8.tar.gz
cd nginx-1.2.8
./configure --prefix=/usr/local/nginx
make
make install
假如执行configure的时候报错:
则yum -y install pcre-devel
6:启动nginx
确保系统的 80 端口没被其他程序占用,
/usr/local/nginx/sbin/nginx
[root@ser6-70 nginx-1.2.8]# /usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
假如报上面这个错误,请参考:Nginx启动错误:error while loading shared libraries: libpcre.so.1_雅冰石的博客-CSDN博客
检查是否启动成功:
netstat -ano|grep 80 有结果输入说明启动成功,如:
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN off (0.00/0/0)
#注意:如果防火墙已关闭的话,需要开放80端口。
打开浏览器访问此机器的 IP,如果浏览器出现 Welcome to nginx! 则表示 Nginx 已经安装并运行成功。
7 设置开机自动启动
首先,在linux系统的/etc/init.d/目录下创建nginx文件,使用如下命令:
vi /etc/init.d/nginx
在脚本中添加:
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx $nginx_pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
注意:nginxd=/usr/local/nginx/sbin/nginx,nginx_config=/usr/local/nginx/conf/nginx.conf请根据自己服务器的实际情况进行修改。
chmod a+x /etc/init.d/nginx
将nginx加入到rc.local文件中,这样开机的时候nginx就默认启动了
vi /etc/rc.d/rc.local
添加
/etc/init.d/nginx start
保存并退出
chmod +x /etc/rc.d/rc.local
现在就可以用service nginx stop/start看能否关闭/启动nginx.
测试机器的话,可以重启下服务器,验证下是否实现了nginx的自启动。
--本篇文章转自:Nginx安装部署 - ruberzhu - 博客园,
http://blog.163.com/qsc0624@126/blog/static/140324073201312734548701/
并做了些许改动。