一.下载nginx
下载nginx源码包,解压:
[[email protected] ~]# cd /usr/local/src/ [[email protected] src]# wget http://nginx.org/download/nginx-1.6.2.tar.gz[[email protected] src]# tar zxvf nginx-1.6.2.tar.gz [[email protected] src]# cd nginx-1.6.2
二.安装nginx
[[email protected] nginx-1.6.2]# yum install -y pcre-devel[[email protected] nginx-1.6.2]# ./configure --prefix=/usr/local/nginx --with-pcre[[email protected] nginx-1.6.2]# make[[email protected] nginx-1.6.2]# make install
注:1.pcre是用来做正则的
2.我们将ngnix安装在/usr/lcoal/nginx目录下
三.启动nginx
[[email protected] nginx-1.6.2]# cd /usr/local/nginx/ [[email protected] nginx]# /usr/local/nginx/sbin/nginx
注:/usr/local/nginx/sbin/nginx可以启动nginx
查看nginx进程和监听端口:
[[email protected] nginx]# ps aux |grep nginx root 18714 0.0 0.0 5000 628 ? Ss 05:37 0:00 nginx: master process /usr/local/nginx/sbin/nginx nobody 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 [[email protected] nginx]# netstat -lnp |grep nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 18714/nginx
四.nginx启动脚本
nginx默认没有启动脚本,我们去写个:
[[email protected] nginx]# vim /etc/init.d/nginx
写入内容:
#!/bin/bash # chkconfig: - 30 21 # description: http service. # Source Function Library . /etc/init.d/functions # Nginx Settings NGINX_SBIN="/usr/local/nginx/sbin/nginx" NGINX_CONF="/usr/local/nginx/conf/nginx.conf" NGINX_PID="/usr/local/nginx/logs/nginx.pid" RETVAL=0 prog="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=1 esac exit $RETVAL
五.设置为开机自启
[[email protected] nginx]# chmod 755 /etc/init.d/nginx [[email protected] nginx]# /etc/init.d/nginx stop 停止 Nginx: [确定] [[email protected] nginx]# /etc/init.d/nginx start 正在启动 Nginx: [确定] [[email protected] nginx]# chkconfig --add nginx [[email protected] nginx]# chkconfig nginx on
;
时间: 2024-12-29 04:23:24