美文网首页
CentOS6之LNMP(Nginx)

CentOS6之LNMP(Nginx)

作者: 鱼落于天 | 来源:发表于2017-12-01 00:25 被阅读0次

1,准备环境

yum -y install gcc wget gcc-c++ automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel

2.下载NGINX

wget http://nginx.org/download/nginx-1.10.3.tar.gz

3.创建用户

#groupadd www

#useradd -g www www -M -s /sbin/nologin

4.解压,安装

tar xf nginx-1.10.3.tar.gz

./configure \

--prefix=/usr/local/nginx \

--sbin-path=/usr/sbin/nginx \

--conf-path=/etc/nginx/nginx.conf \

--error-log-path=/var/log/nginx/error.log \

--http-log-path=/var/log/nginx/access.log \

--pid-path=/var/run/nginx.pid \

--lock-path=/var/run/nginx.lock \

--http-client-body-temp-path=/var/tmp/nginx/client \

--http-proxy-temp-path=/var/tmp/nginx/proxy \

--http-fastcgi-temp-path=/var/tmp/nginx/fcgi \

--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \

--http-scgi-temp-path=/var/tmp/nginx/scgi \

--user=www \

--group=www \

--with-pcre \

--with-http_v2_module \

--with-http_ssl_module \

--with-http_realip_module \

--with-http_addition_module \

--with-http_sub_module \

--with-http_dav_module \

--with-http_flv_module \

--with-http_mp4_module \

--with-http_gunzip_module \

--with-http_gzip_static_module \

--with-http_random_index_module \

--with-http_secure_link_module \

--with-http_stub_status_module \

--with-http_auth_request_module \

--with-mail \

--with-mail_ssl_module \

--with-file-aio \

--with-ipv6 \

--with-http_v2_module \

--with-threads \

--with-stream \

--with-stream_ssl_module

:如果没有安装 环境会出现一些错误。此外,上述的配置可以百度到底是什么意思

make && make install

安装后 echo $? 如果输出0 则没有问题

mkdir -pv /var/tmp/nginx/client

5.添加脚本

vim /etc/init.d/nginx

内容如下 ============>

#!/bin/sh

#

# nginx - this script starts and stops the nginx daemon

#

# chkconfig:  - 85 15

# description: Nginx is an HTTP(S) server, HTTP(S) reverse \

#              proxy and IMAP/POP3 proxy server

# processname: nginx

# config:      /etc/nginx/nginx.conf

# config:      /etc/sysconfig/nginx

# pidfile:    /var/run/nginx.pid

# Source function library.

./etc/rc.d/init.d/functions

# Source networking configuration.

./etc/sysconfig/network

# Check that networking is up.

["$NETWORKING"="no"]&&exit0

nginx="/usr/sbin/nginx"

prog=$(basename $nginx)

NGINX_CONF_FILE="/etc/nginx/nginx.conf"

[-f/etc/sysconfig/nginx]&&./etc/sysconfig/nginx

lockfile=/var/lock/subsys/nginx

start(){

[-x $nginx]||exit5

[-f $NGINX_CONF_FILE]||exit6

echo-n $"Starting $prog: "

daemon $nginx-c $NGINX_CONF_FILE

retval=$?

echo

[$retval-eq0]&&touch $lockfile

return$retval

}

stop(){

echo-n $"Stopping $prog: "

killproc $prog-QUIT

retval=$?

echo

[$retval-eq0]&&rm-f $lockfile

return$retval

killall-9nginx

}

restart(){

configtest||return$?

stop

sleep1

start

}

reload(){

configtest||return$?

echo-n $"Reloading $prog: "

killproc $nginx-HUP

RETVAL=$?

echo

}

force_reload(){

restart

}

configtest(){

$nginx-t-c $NGINX_CONF_FILE

}

rh_status(){

status $prog

}

rh_status_q(){

rh_status>/dev/null2>&1

}

case"$1"in

start)

rh_status_q&&exit0

$1

;;

stop)

rh_status_q||exit0

$1

;;

restart|configtest)

$1

;;

reload)

rh_status_q||exit7

$1

;;

force-reload)

force_reload

;;

status)

rh_status

;;

condrestart|try-restart)

rh_status_q||exit0

;;

*)

echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"

exit2

esac

《=====

箭头之内的内容

5、赋予脚本执行权限。

# chmod +x /etc/init.d/nginx

6、添加至服务管理列表,设置开机自启。

# chkconfig --add nginx

# chkconfig  nginx on

7、启动服务。

# service nginx start

然后就可以通过IP访问了,但是有一点。要关闭防火墙先

相关文章

网友评论

      本文标题:CentOS6之LNMP(Nginx)

      本文链接:https://www.haomeiwen.com/subject/iuxibxtx.html