Linux项目部署5(安装Nginx的插件)

1 如果没有安装过nginx

1、安装nginx的依赖库

yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel

2、解压安装包

tar -zxvf nginx-1.10.0.tar.gz

3、配置nginx安装包,并指定fastdfs-nginx-model

cd nginx-1.10.0

./configure

--prefix=/opt/nginx

--sbin-path=/usr/bin/nginx

--add-module=/usr/local/leyou/fastdfs-nginx-module/src

注意:在执行./configure配置nginx参数的时候,需要将fastdfs-nginx-moudle源码作为模块编译进去。

4、编译并安装

make && make install

2 如果已经安装过nginx

1、 进入nginx目录:

cd /usr/local/项目名/nginx-1.10.0/

2、 配置FastDFS 模块

./configure

--prefix=/opt/nginx

--sbin-path=/usr/bin/nginx

--add-module=/usr/local/项目名/fastdfs-nginx-module/src

注意:这次配置时,要添加fastdfs-nginx-moudle模块

3、编译,注意,这次不要安装(install)

make

4、替换nginx二进制文件:

备份:

mv /usr/bin/nginx /usr/bin/nginx-bak

用新编译的nginx启动文件替代原来的:

cp objs/nginx /usr/bin/

3 启动nginx

配置nginx整合fastdfs-module模块

我们需要修改nginx配置文件,在/opt/nginx/config/nginx.conf文件中:

vim /opt/nginx/conf/nginx.conf

将文件中,原来的server 80{ ...} 部分代码替换为如下代码:

server {

listen 80;

server_name image.项目名.com;

监听域名中带有group的,交给FastDFS模块处理

location ~/group(0-9)/ {

ngx_fastdfs_module;

}

location / {

root html;

index index.html index.htm;

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

}
启动nginx:

nginx # 启动nginx

nginx -s stop # 停止nginx

nginx -s reload # 重新载入配置文件

可通过ps -ef | grep nginx查看nginx是否已启动成功

4 设置nginx开机启动

创建一个开机启动的脚本:

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" && exit 0

nginx="/usr/bin/nginx"

prog=(basename nginx)

NGINX_CONF_FILE="/opt/nginx/conf/nginx.conf"

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

lockfile=/var/lock/subsys/nginx

make_dirs() {

make required directories

user=`$nginx -V 2>&1 | grep "configure arguments:.*--user=" | sed 's/\^\**--user=\(\^ *\).*/\1/g' -`

if -n "$user" ; then

if -z "\`grep $user /etc/passwd\`" ; then useradd -M -s /bin/nologin $user

fi

options=`$nginx -V 2>&1 | grep 'configure arguments:'`

for opt in $options; do

if \`echo $opt \| grep '.\*-temp-path'\` ; then

value=`echo $opt | cut -d "=" -f 2`

if ! -d "$value" ; then

echo "creating" $value

mkdir -p value \&\& chown -R user $value

fi

fi

done

fi

}

start() {

-x $nginx || exit 5

-f $NGINX_CONF_FILE || exit 6

make_dirs

echo -n "Starting prog: "

daemon nginx -c NGINX_CONF_FILE

retval=$?

echo

$retval -eq 0 && touch lockfile return retval} stop() { echo -n "Stopping prog: " killproc prog -QUIT retval=? echo

$retval -eq 0 && rm -f $lockfile

return $retval

}

restart() {

configtest || return $?

stop

sleep 1

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/null 2>&1

}

case "$1" in

start)

rh_status_q && exit 0

$1

;;

stop)

rh_status_q || exit 0 $1 ;;

restart|configtest)

$1

;;

reload)

rh_status_q || exit 7

$1

;;

force-reload)

force_reload

;;

status)

rh_status

;;

condrestart|try-restart)

rh_status_q || exit 0

;;

*)

echo "Usage: 0

{start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"

exit 2

esac

修改文件权限,并加入服务列表

修改权限

chmod 777 /etc/init.d/nginx

添加到服务列表

chkconfig --add /etc/init.d/nginx

设置开机启动

chkconfig nginx on

相关推荐
CodeYp201927 分钟前
第11讲:应用层协议 HTTP
linux·http
爱和冰阔落27 分钟前
【Linux网络】JsonCpp 怎么实现序列化?从 Request/Response 到网络计算器消息设计
linux·运维·网络·php
我是koten6 小时前
【运维杂谈】K8s遇到Terminating的名称空间删除不了怎么办?(解决方案亲测有效)
linux·运维·服务器·云原生·kubernetes·k8s·名称空间
2601_9679873714 小时前
安装 Redis 或 Redis Stack
linux·windows·redis·macos·安装
feng_you_ying_li14 小时前
linux之数据链路层
linux·网络·智能路由器
GeW15 小时前
高端化走到深处,是数据库和Linux的事
linux
程序员初一16 小时前
Linux 远程桌面有四种做法
linux·ssh
程序开发阿元17 小时前
1C1G 能跑什么:把留常驻服务和不留摆进一张内存表
linux·ssh
xbzb19 小时前
自定义 yum 软件源:Linux 上 createrepo,Windows 上纯 Python 也能造
linux·运维·windows·python·yum·createrepo