美文网首页
2018-05-16

2018-05-16

作者: 勤能补拙_2aa2 | 来源:发表于2018-05-16 17:20 被阅读0次

#安装依赖库


yum install -y pcre-devel zlib-devel

#进入到安装目录


cd /usr/local/src/

#远程下载安装源码


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

#解压


tar zxvf nginx-1.9.9.tar.gz

#进入安装目录


cd nginx-1.9.9

#配置安装信息


./configure \

--user=www \

--group=www \

--prefix=/usr/local/nginx

#编译并安装


make && make install

#启动nginx测试


/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

#编辑启动脚本,将下面的代码粘贴进去


vi /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/local/nginx/sbin/nginx"

prog=$(basename $nginx)

sysconfig="/etc/sysconfig/$prog"

lockfile="/var/lock/subsys/nginx"

pidfile="/usr/local/nginx/logs/nginx.pid"

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

[ -f $sysconfig ] && . $sysconfig

start() {

    [ -x $nginx ] || exit 5

    [ -f $NGINX_CONF_FILE ] || exit 6

    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 -p $pidfile $prog

    retval=$?

    echo

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

    return $retval

}

restart() {

    configtest_q || return 6

    stop

    start

}

reload() {

    configtest_q || return 6

    echo -n $"Reloading $prog: "

    killproc -p $pidfile $prog -HUP

    echo

}

configtest() {

    $nginx -t -c $NGINX_CONF_FILE

}

configtest_q() {

    $nginx -t -q -c $NGINX_CONF_FILE

}

rh_status() {

    status $prog

}

rh_status_q() {

    rh_status >/dev/null 2>&1

}

# Upgrade the binary with no downtime.

upgrade() {

    local oldbin_pidfile="${pidfile}.oldbin"

    configtest_q || return 6

    echo -n $"Upgrading $prog: "

    killproc -p $pidfile $prog -USR2

    retval=$?

    sleep 1

    if [[ -f ${oldbin_pidfile} && -f ${pidfile} ]];  then

        killproc -p $oldbin_pidfile $prog -QUIT

        success $"$prog online upgrade"

        echo

        return 0

    else

        failure $"$prog online upgrade"

        echo

        return 1

    fi

}

# Tell nginx to reopen logs

reopen_logs() {

    configtest_q || return 6

    echo -n $"Reopening $prog logs: "

    killproc -p $pidfile $prog -USR1

    retval=$?

    echo

    return $retval

}

case "$1" in

    start)

        rh_status_q && exit 0

        $1

        ;;

    stop)

        rh_status_q || exit 0

        $1

        ;;

    restart|configtest|reopen_logs)

        $1

        ;;

    force-reload|upgrade)

        rh_status_q || exit 7

        upgrade

        ;;

    reload)

        rh_status_q || exit 7

        $1

        ;;

    status|status_q)

        rh_$1

        ;;

    condrestart|try-restart)

        rh_status_q || exit 7

        restart

        ;;

    *)

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

        exit 2

esac

#注意权限


chmod +x /etc/init.d/nginx

#启动测试


service nginx restart

#设置开机启动


chkconfig nginx on

#开放防火墙,配置80端口访问


iptables -I INPUT -p tcp --dport 80 -j ACCEPT

#保存配置文件,让其生效


service iptables save

#无法解析php文件

#在/usr/local/nginx/html/ 建立phpinfo.php文件,访问发现php文件无法解析

#修改nginx.conf文件


vi /usr/local/nginx/conf/nginx.conf

#加入


location ~ \.php$ {

        fastcgi_pass  127.0.0.1:9000;

        fastcgi_index  index.php;

        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;

        include        fastcgi_params;

}

#重启nginx


service nginx restart

相关文章

  • 2018-05-30

    2018-05-16 李晓红Dorothy 2018-05-16 07:10 · 字数 265 · 阅读 0 · ...

  • 2018-05-17

    2018-05-16 不与众生 已关注 2018-05-16 16:07 · 字数 558 · 阅读 2 · 日记...

  • 海外版本首次开机无法注册Volte

    图片截图显示状态:2018-05-16 17:57:31 首次开机没有注册上Volte 2018-05-16 1...

  • 2018-05-16

    2018-05-16 戴师傅简书作者 2018-05-16 20:19 打开App (稻盛哲学学习会)打卡第59天...

  • 2018-05-17

    JavaScript 六、数组API 不与众生 已关注 2018-05-16 19:57 · 字数 1140 · ...

  • http理解(下)

    title: http 理解(下)date: 2018-05-16 10:13:42tags: http Web的...

  • 2018-05-20 安卓使用vlc播放本地视频

    2018-05-16添加libvlc.aar后 https://www.jianshu.com/p/f961ffc...

  • linux 实验楼01

    title: linux 实验楼01date: 2018-05-16 16:34:32categories: [L...

  • 【纸短情长】青春

    2018-05-16 22:00 · 字数 290 · 阅读 130 · 浅水涅槃的小窝 文/浅水涅槃 一 青春的...

  • 日精进打卡(第313天)

    2018-05-16 姓名:李义 公司:........ 组别:259期利他二组 【知~学习】 背诵 六项精进大纲...

网友评论

      本文标题:2018-05-16

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