RedHat7安装Nginx及第三方模块(亲测,亚马逊服务器安装)

9 篇文章 0 订阅

RedHat7安装Nginx及第三方模块

编译安装Nginx

  1. 先安装编译过程中所需依赖包
    # yum -y install gcc pcre-devel openssl-devel zlib-devel
  2. 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
    备注:如果解压失败,遇到如下问题
    tar (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
    解决方法:安装bzip2
    # yum install bzip2
  3. 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
  4. 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
  5. 下载Nginx源码包
    # wget http://nginx.org/download/nginx-1.9.9.tar.gz
  6. 解压Nginx源码包
    # tar -zxvf nginx-1.9.9.tar.gz && cd 
    nginx-1.9.9
  7. 编译安装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

#/usr/sbin/groupadd -f www

#/usr/sbin/useradd -g www www

在重启云主机(系统)之后,执行 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

--------------------- 本文来自 广慕君 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/qq_37054356/article/details/77126707?utm_source=copy

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值