第一步安装nginx前所需要的环境配置信息
1:检查当前pcre环境
[root@www ~]# rpm -qa pcre pcre-devel
pcre-devel-7.8-6.el6.x86_64
出现上面命令的结果说明环境存在,不存在执行以下命令安装
采用yum安装
[root@www ~]# yum install pcre pcre-devel -y
[root@www ~]# rpm -qa pcre pcre-devel
pcre-7.8-7.el6.x86_64
pcre-devel-7.8-7.el6.x86_64
采用下载安装包安装
wget http://sourceforge.net/projects/pcre/files/pcre/7.80/pcre-7.80.tar.gz
tar zxf pcre-7.80.tar.gz
cd pcre-7.80
./configure
make && make install
cd ../
安装完成检查环境是否成功
2:安装openssl-devel,安装openssl-devel的命令及检查命令如下:
[root@www ~]# yum install -y openssl openssl-devel
[root@www ~]# rpm -qa openssl openssl-devel
openssl-devel-1.0.1e-30.el6.8.x86_64
openssl-1.0.1e-30.el6.8.x86_64
先检查是否已经安装,没有安装直接采用yum方式安装openssl-devel
3:安装gcc环境
yum -y install gcc gcc-c++ autoconf automake make
以上环境安装成功之后下面就开始安装nginx
4:开始安装Nginx
下载nginx到系统中:
wget http://nginx.org/download/nginx-1.6.3.tar.gz
#下载软件包,进入http://nginx.org/download/ 复制对应版本的链接地址。提示,如果发现Nginx软件下载地址已不可用,可能版本已更新,可去官方地址http://www.nginx.org下载。
5:安装的操作过程演示
[root@www tools]# wget -q http://nginx.org/download/nginx-1.6.3.tar.gz
[root@www tools]# ls -l nginx-1.6.3.tar.gz
-rw-r--r--1 root root 804164 11月 23 15:26 nginx-1.6.3.tar.gz
[root@www tools]# cd nginx-1.6.3
[root@www nginx-1.6.3]#./configure --user=nginx --group=nginx --prefix= /usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
[root@www nginx-1.6.3]# make
[root@www nginx-1.6.3]# make install
[root@www nginx-1.6.3]# ln -s /usr/local/nginx-1.6.3 /usr/local/nginx
[root@www nginx-1.6.3]# ls -l /usr/local/nginx/总用量 16
drwxr-xr-x. 2 root root 4096 7月 20 11:19 conf
drwxr-xr-x. 2 root root 4096 7月 20 11:19 html
drwxr-xr-x. 2 root root 4096 7月 20 11:19 logs
drwxr-xr-x. 2 root root 4096 7月 20 11:19 sbin
安装过程出现如下错误:
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules,or install the OpenSSL library
into the system,or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.
执行命令
yum install openssl openssl-devel-y
6:启动并检查安装结果
[root@zero init.d]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@zero init.d]# /usr/local/nginx/sbin/nginx
检查是否启动成功
[root@zero init.d]# ps -ef|grep nginx
root 39727 1 0 13:00 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 39728 39727 0 13:00 ? 00:00:00 nginx: worker process
root 39808 3530 0 13:01 pts/0 00:00:00 grep nginx
说明nginx启动成功,通过netstat -ntlp 查看nginx占用的端口号80
[root@zero init.d]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 29773/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 2026/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2353/master
tcp 0 0 0.0.0.0:48705 0.0.0.0:* LISTEN 1972/rpc.statd
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1910/rpcbind
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 39727/nginx
到此nginx基本部署已经完成,下面讲解Nginx 添加到 service 启动
第一步:编辑nginx
[root@zero /]# vi /etc/init.d/nginx
第二步:添加一下代码:
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
#
# 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
########### need to modify the path ###################
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/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 /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog: "
$nginxd -s reload
#if your nginx version is below 0.8, please use this command: "kill -HUP `cat ${nginx_pid}`"
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
保存当前文件代码:wq
第三步:执行一下操作
[root@zero /]# cd /etc/rc.d/init.d
[root@zero init.d]# chmod +x nginx
[root@zero init.d]# /sbin/chkconfig --level 345 nginx on
任何位置都能运行 service nginx start 可选 start | stop | restart | reload | status | help
执行效果代码如下:
[root@zero init.d]# service nginx stop
/etc/init.d/nginx: line 1: nx: command not found
Stopping nginx: [ OK ]
[root@zero init.d]# service nginx start
/etc/init.d/nginx: line 1: nx: command not found
Starting nginx: [ OK ]
[root@zero init.d]# service nginx restart
/etc/init.d/nginx: line 1: nx: command not found
Stopping nginx: [ OK ]
Starting nginx: [ OK ]
[root@zero init.d]# service nginx status
/etc/init.d/nginx: line 1: nx: command not found
nginx (pid 40241 40239) is running...
[root@zero init.d]#
本节nginx部署已经讲完,互相学习不懂的可以留言