一.下载nginx
下载nginx源码包,解压:
[root@huh ~]# cd /usr/local/src/[root@huh src]# wget http://nginx.org/download/nginx-1.6.2.tar.gz [root@huh src]# tar zxvf nginx-1.6.2.tar.gz [root@huh src]# cd nginx-1.6.2
二.安装nginx
[root@huh nginx-1.6.2]# yum install -y pcre-devel [root@huh nginx-1.6.2]# ./configure --prefix=/usr/local/nginx --with-pcre --with-http_stub_status_module [root@huh nginx-1.6.2]# make [root@huh nginx-1.6.2]# make install
注:1.pcre是用来做正则的
2.我们将ngnix安装在/usr/lcoal/nginx目录下
三.启动nginx
[root@huh nginx-1.6.2]# cd /usr/local/nginx/[root@huh nginx]# /usr/local/nginx/sbin/nginx
注:/usr/local/nginx/sbin/nginx可以启动nginx
查看nginx进程和监听端口:
[root@huh nginx]# ps aux |grep nginxroot 18714 0.0 0.0 5000 628 ? Ss 05:37 0:00 nginx: master process /usr/local/nginx/sbin/nginxnobody 18715 0.0 0.0 5184 976 ? S 05:37 0:00 nginx: worker process root 18719 0.0 0.0 6048 784 pts/0 S+ 05:41 0:00 grep --color nginx[root@huh nginx]# netstat -lnp |grep nginxtcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 18714/nginx
四.nginx启动脚本
nginx默认没有启动脚本,我们去写个:
[root@huh nginx]# vim /etc/init.d/nginx
写入内容:
#!/bin/bash# chkconfig: - 30 21# description: http service.# Source Function Library. /etc/init.d/functions# Nginx SettingsNGINX_SBIN="/usr/local/nginx/sbin/nginx"NGINX_CONF="/usr/local/nginx/conf/nginx.conf"NGINX_PID="/usr/local/nginx/logs/nginx.pid"RETVAL=0prog="Nginx"start() { echo -n $"Starting $prog: " mkdir -p /dev/shm/nginx_temp daemon $NGINX_SBIN -c $NGINX_CONF RETVAL=$? echo return $RETVAL}stop() { echo -n $"Stopping $prog: " killproc -p $NGINX_PID $NGINX_SBIN -TERM rm -rf /dev/shm/nginx_temp RETVAL=$? echo return $RETVAL}reload(){ echo -n $"Reloading $prog: " killproc -p $NGINX_PID $NGINX_SBIN -HUP RETVAL=$? echo return $RETVAL}restart(){ stop start}configtest(){ $NGINX_SBIN -c $NGINX_CONF -t return 0}case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) restart ;; configtest) configtest ;; *) echo $"Usage: $0 {start|stop|reload|restart|configtest}" RETVAL=1esacexit $RETVAL
五.设置为开机自启
[root@huh nginx]# chmod 755 /etc/init.d/nginx [root@huh nginx]# /etc/init.d/nginx stop停止 Nginx: [确定][root@huh nginx]# /etc/init.d/nginx start正在启动 Nginx: [确定][root@huh nginx]# chkconfig --add nginx[root@huh nginx]# chkconfig nginx on
;