nginx

Centos下重新编译nginx并添加模块

1106
0
2017-01-04

由于一些原因,我需要重新编译nginx并添加http_sub_module模块

首先,执行./nginx -V,把configure arguments:的值记录下来,一会儿要用到
然后,找到当初安装nginx时的源码,cd到源码目录下(或者下载一个源码并解压)
执行编译

./configure [参数值]

上面的**[参数值]**就是刚才configure arguments的值,再加上我们所需要的http_sub_module模块,那么我当时完整的命令是这样的

./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module

然后make一下,注意 不要 make install,不然就覆盖安装现有nginx了
make完之后在objs目录下就可以看到新编译的nginx文件了
我们cd到objs目录测试一下新编译的nginx

./nginx -t

如果看到

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

那就表示测试通过可以使用了
此时如果直接把新nginx cp过去替换的话多半会报错

cp: cannot create regular file '/usr/local/nginx/sbin/nginx': Text file busy

因为旧nginx正在运行,无法替换
所以我们得停掉、备份、替换、启动

service nginx stop
cp /usr/bin/nginx /usr/bin/nginx_bak
cp ./nginx /usr/bin/nginx
service nginx start

至此,添加模块成功,反代也正常运行了。可喜可贺、可喜可贺

昵称
邮箱
网址