Linux安装Nginx

安装pcre

下载:https://sourceforge.net/projects/pcre/files/pcre/
解压并安装:

tar zxf pcre-8.42.tar.gz
cd pcre-8.42/
./configure
 make && make install

安装nginx

下载: http://nginx.org/en/download.html

添加nginx用户

groupadd www
useradd -s /sbin/nologin -g www www

安装nginx

[root@SZ1PRDSES00AP0002 nginx-1.8.1]# cd /usr/local/  
tar zxf nginx-1.6.0.tar.gz  
cd nginx-1.8.1/  
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6   
make && make install

运行nginx

执行完上面安装步骤,ng安装完成目录会在user/local/nginx下;
进入到 /usr/local/nginx/sbin目录下,运行./nginx 命令

[root@SZ1PRDSES00AP0002 nginx-1.8.1]# cd /usr/local/nginx
./nginx -c /usr/local/nginx/conf/nginx.conf

检验

打开浏览器输入ip访问,如果出现ng界面,说明安装成功。 输入图片说明

命令与快捷方式

命令

nginx 安装完毕,可以使用以下命令启动、停止或重启

  • 启动
    启动代码格式:nginx安装目录地址 -c nginx配置文件地址
[root@SZ1PRDSES00AP0002 nginx-1.8.1]# cd /usr/local/nginx
./nginx -c /usr/local/nginx/conf/nginx.conf
  • 停止

从容停止:

ps -ef|grep nginx
kill -QUIT 进程号

快速停止:

ps -ef|grep nginx
kill -TERM 进程号

强制停止:

pkill -9 nginx
  • 重启
[root@SZ1PRDSES00AP0002 nginx-1.8.1]# cd /usr/local/nginx
./nginx -s reload

快捷方式

新建快捷方式,可以使用快捷方式启动、停止或重启ng
进入到/etc/init.d/ 目录下 新建一个nginx文本

cd /etc/init.d
vim nginx

添加以下内容

# chkconfig: - 85 15  
# description: nginx is a World Wide Web server. It is used to serve  
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=nginx
NGINX_BIN=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
PIDFILE=/usr/local/nginx/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

case "$1" in
	start)
		echo -n "Starting $NAME... "

		if netstat -tnpl | grep -q nginx;then
		echo "$NAME (pid `pidof $NAME`) already running."
		exit 1
		fi

		$NGINX_BIN -c $CONFIGFILE

		if [ "$?" != 0 ] ; then
			echo " failed"
			exit 1
		else
			echo " done"
		fi
	;;

	stop)
		echo -n "Stoping $NAME... "

		if ! netstat -tnpl | grep -q nginx; then
			echo "$NAME is not running."
			exit 1
		fi

		$NGINX_BIN -s stop

		if [ "$?" != 0 ] ; then
			echo " failed. Use force-quit"
			exit 1
		else
			echo " done"
		fi
	;;

	status)
		if netstat -tnpl | grep -q nginx; then
			PID=`pidof nginx`
			echo "$NAME (pid $PID) is running..."
		else
			echo "$NAME is stopped"
			exit 0
		fi
	;;

	force-quit)
		echo -n "Terminating $NAME... "

		if ! netstat -tnpl | grep -q nginx; then
			echo "$NAME is not running."
			exit 1
		fi

		kill `pidof $NAME`

		if [ "$?" != 0 ] ; then
			echo " failed"
			exit 1
		else
			echo " done"
		fi
	;;

	restart)
		$SCRIPTNAME stop
		sleep 1
		$SCRIPTNAME start
	;;

	reload)
		echo -n "Reload service $NAME... "

		if netstat -tnpl | grep -q nginx; then
			$NGINX_BIN -s reload
			echo " done"
		else
			echo "$NAME is not running, can't reload."
			exit 1
		fi
	;;

	configtest)
		echo -n "Test $NAME configure files... "

		$NGINX_BIN -t
	;;

	*)
		echo "Usage: $SCRIPTNAME {start|stop|force-quit|restart|reload|status|configtest}"
		exit 1
	;;

esac

保存并授权

[root@SZ1PRDSES00AP0002 init.d]# chmod +x nginx
[root@SZ1PRDSES00AP0002 init.d]# chkconfig --level 345 nginx on

然后你就可以使用快捷命令启动、停止、或是重启了

停止
[root@SZ1PRDSES00AP0002 init.d]# service nginx stop
Stoping nginx...  done

启动
[root@SZ1PRDSES00AP0002 init.d]# service nginx start
Starting nginx...  done

重启
[root@SZ1PRDSES00AP0002 init.d]# service nginx restart
Stoping nginx...  done
Starting nginx...  done

部署静态网页

网页放在/usr/local/nginx/html目录下就好了

转载于:https://my.oschina.net/u/3457546/blog/1802661

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值