RedHat7安装Nginx及第三方模块
编译安装Nginx
- 先安装编译过程中所需依赖包
# yum -y install gcc pcre-devel openssl-devel zlib-devel - jemalloc(更好的内存管理)
# wget http://www.canonware.com/download/jemalloc/jemalloc-4.0.4.tar.bz2
# tar -jxvf jemalloc-4.0.4.tar.bz2 && cd jemalloc-4.0.4
# ./configure
# make && make install
# echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf
# ldconfig
备注:如果解压失败,遇到如下问题
解决方法:安装bzip2tar (child): lbzip2: Cannot exec: No such file or directory tar (child): Error is not recoverable: exiting now tar: Child returned status 2 tar: Error is not recoverable: exiting now
# yum install bzip2 - lua模块
lua-nginx-module来自大牛agentzh的开源项目,在Nginx中嵌入Lua语言,使之可以支持强大Lua语法
1. 下载LuaJIT2.0并安装
切换到上级目录 # cd ..
# wget http://luajit.org/download/LuaJIT-2.0.4.tar.gz
# tar -zxvf LuaJIT-2.0.4.tar.gz && cd LuaJIT-2.0.4
# make && make install
2. 下载并解压ngx_devel_kit和lua-nginx-module
切换到上级目录 # cd ..
下载ngx_devel_kit-0.2.19.tar.gz (https://codeload.github.com/simpl/ngx_devel_kit/tar.gz/v0.2.19)
解压 # tar -zxvf ngx_devel_kit-0.2.19.tar.gz
下载lua-nginx-module-0.9.20rc2.tar.gz (https://codeload.github.com/openresty/lua-nginx-module/tar.gz/v0.9.20rc2)
解压 # tar -zxvf lua-nginx-module-0.9.20rc2.tar.gz
3. 导入环境变量
# export LUAJIT_LIB=/usr/local/lib
# export LUAJIT_INC=/usr/local/include/luajit-2.0 - ngx_cache_purge模块(Nginx清除缓存模块)
切换到上级目录 # cd ..
下载 # wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
解压 # tar -zxvf ngx_cache_purge-2.3.tar.gz - 下载Nginx源码包
# wget http://nginx.org/download/nginx-1.9.9.tar.gz - 解压Nginx源码包
# tar -zxvf nginx-1.9.9.tar.gz && cd nginx-1.9.9 - 编译安装Nginx
# ./configure \
--sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/var/run/nginx.pid \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-threads \
--with-stream \
--with-stream_ssl_module \
--with-ipv6 \
--with-http_v2_module \
--add-module=../ngx_cache_purge-2.3 \
--add-module=../lua-nginx-module-0.9.20rc2 \
--add-module=../ngx_devel_kit-0.2.19 \
--with-ld-opt='-ljemalloc' \
--with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'
# make -j2 && make install
此时继续照转载出处:https://www.cnblogs.com/edward2013/p/5020874.html 继续配置
然后启动
此时:已经安装好了,欿nginx目录下,./nginx -s reload ./nginx -t 启动和检查配置
/nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory
是没有找到共享链接库的原因
# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
# echo "/usr/local/lib" >> /etc/ld.so.conf
# ldconfig
启动nginx,成功!
inux 64系统中安装nginx1.3时如果出现错误:nginx: [emerg] getpwnam(“www”) failed
解决方法1:
在nginx.conf中 把user nobody的注释去掉既可
解决方法2:
错误的原因是没有创建www这个用户,应该在服务器系统中添加www用户组和用户www,如下命令:
1 2 |
|
在重启云主机(系统)之后,执行 nginx -t 是OK的,然而在执行 nginx -s reload 的时候报错
nginx: [error] invalid PID number “” in “/run/nginx.pid”
经过查找,找到http://www.cnblogs.com/yuqianwen/p/4285686.html
需要先执行
./nginx -c nginx.conf的目录(nginx.conf文件的路径可以从nginx -t的返回中找到。)
nginx -s reload
--------------------- 本文来自 广慕君 的优快云 博客 ,全文地址请点击:https://blog.youkuaiyun.com/qq_37054356/article/details/77126707?utm_source=copy