app单点部署流程

2018/5/20 posted in  OPS

部署流程

备份chupinxiu.com.conf配置文件

在web1上创建负载切换的lua文件:/opt/openresty-1.13.6.1/lua/php-fpm-upstream.lua

if ngx.var.project == "apipro" then
    return ngx.exec("@single")
else
    return ngx.exec("@mutiple")
end

编辑nginx配置文件: /opt/openresty-1.13.6.1/nginx/conf/vhost/chupinxiu.com.conf

配置两个php的upstream

upstream php-fpm-backend-mutiple {
    server unix:/var/run/php-fpm.sock weight=5; # web1
    server 10.135.216.41:9000 weight=5; # web2
}
upstream php-fpm-backend-single {
    server unix:/var/run/php-fpm.sock; # web1
}

为两个upstream配置两个location

    location @mutiple {
        root $dest;
        proxy_set_header Host $host;
        fastcgi_pass   php-fpm-backend-mutiple;
        fastcgi_index  index.php;
        include        fastcgi.conf;
    }

    location @single {
        root $dest;
        proxy_set_header Host $host;
        fastcgi_pass   php-fpm-backend-single;
        fastcgi_index  index.php;
        include        fastcgi.conf;
    }

normal location中使用php-fpm-upstream.lua选择upstream

    location @normal {
        content_by_lua_file    /opt/openresty-1.13.6.1/lua/php-fpm-upstream.lua;
    }

重启nginx

回滚流程

删除chupinxiu.com.conf

将chupinxiu.com.conf配置文件恢复

删除 /opt/openresty-1.13.6.1/lua/php-fpm-upstream.lua;

重启nginx