@yibo
2017-05-11T07:09:51.000000Z
字数 2503
阅读 1050
nginx
以添加 VeryNginx 扩展,并将 Nginx 从 1.10.0 升级到 1.13.0 为例
wget https://github.com/alexazhou/VeryNginx/archive/v0.3.3.zip
unzip v0.3.3.zip
cd VeryNginx-0.3.3/
python install.py install verynginx
cd ..
安装 VeryNginx 用到了 Python 脚本,但这个项目跟 Python 没有半毛钱关系,不信可以看下 install.py
中的 install_verynginx
方法,只做了拷贝文件和修改配置目录权限两件事。
VeryNginx 默认会被装到 /opt/verynginx/
目录,本文使用默认配置。
VeryNginx 依赖的 http_stub_status_module
和 http_ssl_module
只需要在 configure 时加上就可以。lua-nginx-module
稍微麻烦一点,它有以下依赖:
下面分别来搞定它们。本文使用 CentOS 7,全部采用默认路径安装。如果你的环境跟我不一样,一些命令请自行调整。
下载并安装 LuaJIT:
wget http://luajit.org/download/LuaJIT-2.1.0-beta3.zip
unzip LuaJIT-2.1.0-beta3.zip
cd LuaJIT-2.1.0-beta3/
make
make install
cd ..
设置环境变量:
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.1/
下载并解压 ngx_devel_kit:
wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.zip
unzip v0.3.0.zip
下载并解压 ngx_lua:
wget https://github.com/openresty/lua-nginx-module/archive/v0.10.9rc1.zip
unzip v0.10.9rc1.zip
cd /opt/source/
wget http://nginx.org/download/nginx-1.13.0.tar.gz
tar -zxvf nginx-1.13.0.tar.gz
cd nginx-1.13.0
./configure \
--prefix=/opt/nginx-1.13.0 \
--user=nginx \
--group=nginx \
--with-stream \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_realip_module \
--add-module=../ngx_cache_purge-2.3 \
--with-http_sub_module \
--with-http_v2_module \
--with-ld-opt="-Wl,-rpath,/usr/local/lib/" \
--add-module=../ngx_devel_kit-0.3.0 \
--add-module=../lua-nginx-module-0.10.9rc1
make
注意:这里只进行 make 操作,不用 make install
将之前老版本的 nginx copy 一份,在此副本上进行操作
cp -r /opt/nginx-1.10.0 /opt/nginx-1.13.0
rm -rf /opt/nginx
ln -s /opt/nginx-1.13.0 /opt/nginx
cd /opt/nginx/sbin
mv nginx nginx.old
cp /opt/source/nginx-1.13.0/objs/nginx /opt/nginx/sbin/
让nginx把nginx.pid文件修改成nginx.pid.oldbin,随即启动nginx,实现不间断。
在 nginx-1.13.0 的源码文件夹内执行 make upgrade 等效于以下命令。不过 make upgrade 在 nginx 新老版本不是同一目录的情况下,会出错。
kill -USR2 `cat /opt/nginx-1.13.0/logs/nginx.pid` 更新配置文件,这个 pid 文件实际是从老版本复制过来的
kill -QUIT `cat /opt/nginx-1.10.0/logs/nginx.pid.oldbin` 优雅的关闭
在 Nginx 中引入 VeryNginx 的配置文件,就可以让 VeryNginx 工作起来。首先要修改的是 Nginx 的主配置。
在主配置文件的最外层,加入以下配置:
include /opt/verynginx/verynginx/nginx_conf/in_external.conf;
在主配置的 http
段落中,加入以下配置:
include /opt/verynginx/verynginx/nginx_conf/in_http_block.conf;
在具体站点配置的 server
段落中,加入以下配置:
include /opt/verynginx/verynginx/nginx_conf/in_server_block.conf;
加完之后,建议通过 -t
参数确保配置无误:
/usr/local/nginx/sbin/nginx -t
如果提示 test is successful
,说明配置无误,可以重启 Nginx 服务;否则请根据提示排查。
如果一切顺利,访问 http://yourdomain.com/verynginx/index.html
就可以见到 VeryNginx 的 Web 控制面板。默认用户名和密码都是 verynginx
,登录后请务必修改。