[Nginx基础]-- 源码安装nginx

本文详细介绍了Nginx和Tengine的安装过程,包括下载、解压、配置及启动等步骤,并提供了遇到常见问题时的解决方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、安装nginx

安装步骤:

1\\下载使用稳定版本:nginx-1.8.1.tar.gz

2\\使用ssh工具复制到/home目录下,解压—》tar –zxvf  nginx-1.8.1.tar.gz 

3\\进入解压后的目录: cd  /home/nginx-1.8.1 --à执行预编译命令

#./configure  --prefix=/home/nginx(此处的/home/nginx目录是安装目录) ---à回车

A、如果预编译,检查没有错误则说明正确!可以下一步安装

B、如果有错误,查看当前版本---》yum info ?(如zlib)

(1)然后安装对应得版本,本次安装时,需要jdk对应nginx版本都是开发者版本:

yum y install  pcre-develyum y install  zlib-devel

强制卸载: rpm -e --nodeps pcre 

           (2)再检查./configure  --prefix=/home/nginx没有错误

4\\在刚才的解压目录下(cd  /home/nginx-1.8.1)下,执行make命令---》然后make install

5\\访问不成功,说明防火墙开着

            需要关闭防火墙---------》service iptables status  -------àservice iptables stop(close)

            查看开机是否启动à chkconfig  --list | grep ntp----à关闭chkconfig  iptables off(on)

           查看进程—》[root@node4 logs]# ps aux | grep nginx-----》杀死进程:kill pid

 6\\浏览器访问:192.168.142.102即可

 

优点:可以自定义添加nginx的功能模块

 

二、安装tengine

 

A---解压tengine.tar.gz到home目录下

B---在解压目录下,执行预编译检查

./configure \

  --prefix=/opt/sxt/soft/tengine-2.1.0/ \

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

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

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

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

  --with-http_ssl_module \

  --with-http_flv_module \

  --with-http_stub_status_module \

  --with-http_gzip_static_module \

  --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 \

  --with-pcre

(a)检查正常:在当前解压目录下执行”make && make install ”

(b)如果检查异常:根据需要安装开发者包

C---添加到注册表:vim /etc/network 

D---进入” /etc/network”目录下,新建nginx,将nginx里面的内容(查看本文备注)拷贝进来,

注意三点,a)新建文件,b)编辑模式,c)这里要修改两个参数

nginx="/opt/sxt/soft/tengine-2.1.0/sbin/nginx"

NGINX_CONF_FILE="/opt/sxt/soft/tengine-2.1.0/conf/nginx.conf"

E---在” /etc/network”目录下,修改权限可执行,#chmod 755 nginx

F---递归调用创建需要的文件夹  mkdir  –p  /var/tmp/nginx/client/

G --service nginx start(stop,restart)  启动正常结果

the configuration file /opt/sxt/soft/tengine-2.1.0/conf/nginx.conf syntax is ok

configuration file /opt/sxt/soft/tengine-2.1.0/conf/nginx.conf test is successful

Stopping nginx:                                            [  OK  ]

Starting nginx:                                            [  OK  ]

M不用yum安装----》原因源安装是可以安装模块,而yum则不行,必须卸载后才能重新安装

 

 

 

 

备注一:tengine的配置:新建的nginx文件在---》 cd /etc/network目录下

#!/bin/bash

#

# chkconfig: - 85 15

# description: nginx is a World Wide Web server. It is used to serve

# 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/tengine-2.1/sbin/nginx"

prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/tengine-2.1/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:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`

#   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

#}

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: "

#  -HUP是nginx平滑重启参数  

    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

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

oo寻梦in记

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值