最新消息:欢迎加入小松的QQ群一起讨论一起学习,搜索页面修改成lua+ElasticSearch,使用php这个页面速度相对慢一点,优化之后速度杠杠的,如有问题请加群联系我

nginx 替换成openresty

Nginx 257浏览 0评论

把nginx服务器替换成openresty原来以为很复杂,操作过之后发现很简单,主要是想用redis+lua来提高负载【推荐阅读:wordpress博客极速优化】下面开始时间操作

openresty安装

openresty官方下载地址: http://openresty.org/cn/download.html
我安装的是最新版本openresty-1.11.2.2

wget https://openresty.org/download/openresty-1.11.2.2.tar.gz
tar -xzvf openresty-1.11.2.2.tar.gz
cd openresty-1.11.2.2
./configure --user=www --group=www --prefix=/usr/local/openresty --with-luajit --without-http_redis2_module --with-http_stub_status_module  --with-http_v2_module --with-http_gzip_static_module  --with-http_sub_module --with-openssl=/root/openssl-1.0.2j
gmake
gmake install

设置openresty使用服务启动

vi /etc/init.d/openresty
把下面的内容复制到 openresty 文件里

#! /bin/sh
# chkconfig: 2345 55 25
# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
# run 'update-rc.d -f nginx defaults', or use the appropriate command on your
# distro. For CentOS/Redhat run: 'chkconfig --add nginx'

### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO

# Author:   licess
# website:  http://www.phpsong.com

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=nginx
NGINX_BIN=/usr/local/openresty/nginx/sbin/$NAME
CONFIGFILE=/usr/local/openresty/nginx/conf/$NAME.conf
PIDFILE=/usr/local/openresty/nginx/logs/$NAME.pid

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)
        $0 stop
        sleep 1
        $0 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: $0 {start|stop|force-quit|restart|reload|status|configtest}"
        exit 1
        ;;

esac

保存文件
这样就可以使用服务的方式来操作openresty
把原来nginx的配置文件复制到openresty目录下

cp /usr/local/nginx/conf/*.conf /usr/local/openresty/nginx/conf/
cp -r /usr/local/nginx/conf/vhost /usr/local/openresty/nginx/conf

请根据自己的服务器情况来
修改配置文件

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

修改pid的路径为

pid   /usr/local/openresty/nginx/logs/nginx.pid;

停止原来的nginx服务器在启动openresty

service nginx stop
service openresty start

openresty服务器管理命令

service openresty start //启动openresty
service openresty stop //停止openresty
service openresty restart //重启openresty

PS.启动之前要把原来的nginx停止,因为都侦听80端口,端口会冲突

到此以成功的将nginx替换成openresty

疑问:最新版的openresty发现,https的时候响应头显示server 为nginx,如果修改成http,server为openresty,这个我实际测试过

原来是openresty 在支持http2的时候 响应头header server会修改成nginx,跟https没有关系

QQ交流群:136351212(满) 455721967

如无特别说明,本站文章皆为原创,若要转载,务必请注明以下原文信息:
转载保留版权:小松博客» nginx 替换成openresty
本文链接地址:https://www.phpsong.com/2936.html

发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
木有头像就木有JJ!点这里按步骤申请Gravatar头像吧!