非root用户下安装nginx及运行

        本章主要讲如何在无root权限(包含无sudo权限)条件下于centos命令行中安装nginx以及在大于1024的端口(这里用8080)上运行。两种方式,一是下载预编译好的rpm包安装(如果是通过下载rpm方式安装,首先要找对应centos版本的rpm包),二是下载源码后自己编译(要依赖pcre库、zlib库等)。

一、 安装依赖

        1、 下载nginx依赖包


            pcre 下载地址:www.pcre.org
            zlib 下载地址:www.zlib.org ,
            openssl 下载地址:www.openssl.org


        2、 安装依赖

        2.1  PCRE库的安装


        解压:

                unzip pcre2-10.31.zip,解压目录为:pcre2-10.31

                然后进入到 cd pcre2-10.31,进行配置、编译、安装

        配置

                ./configure或./config

        编译

                make

        安装

                make install

        备注:也可编译安装一起进行 make && make install

 

        2.2  OpenSSL库的安装

        解压:

                tar –zxvf openssl-1.1.1-pre7.tar.gz,解压目录为:openssl-1.1.1-pre7

                然后进入到 cd openssl-1.1.1-pre7,进行配置、编译、安装

        配置

                ./configure或./config

        编译

                make

        安装

                make install

        备注:也可编译安装一起进行 make && make install

 

        1.3 安装zlib库安装

        解压:

                tar –zxvf zlib-1.2.11.tar.gz,解压目录为:zlib-1.2.11

                然后进入到 cd zlib-1.2.11,进行配置、编译、安装

        配置

                ./configure或./config

        编译

                make

        安装

                make install

        备注:也可编译安装一起进行 make && make install

二、 安装nginx

        解压 nginx : 

# 解压
tar -zxvf nginx-1.15.0.tar.gz

        安装 nginx :

# 进入解压目录
cd ~/tools/nginx-1.15.0
#  --with-pcre=后的路径为pcre的解压后的源路径
#  --prefix=路径为nginx想要安装到的目录
./configure  --with-http_stub_status_module  --prefix=/home/redhat/tools/nginx  --with-pcre=/home/redhat/tools/pcre2-10.31

        编译与安装 :

# 编译
  make

# 安装
  make install

# make && make install

 

三、常见问题

        1、 不改配置无法正常   

        提示:

nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)

        原因:
                启动不了的,因为非root用户启动不了1024以下端口
        解决方案:
                修改一下nginx.conf监听端口为1024以上端口,重新启动nginx

    2、 直接安装nginx提示缺少依赖

        提示:

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

        原因:
                因为Nginx需要其他第三方库的支持,比如rewrite模块需要pcre库,ssl需要openssl库等。
        解决方案:
                安装所需的pcre(www.pcre.org),zlib(www.zlib.org),openssl(www.openssl.org)等。

    3、 ngixn 进行make时报错

        提示:

make -f objs/Makefile
make[1]: Entering directory `/home/redhat/tools/nginx'
cd /home/redhat/tools/nginx/zzw_other/pcre-8.10 \
        && if [ -f Makefile ]; then make distclean; fi \
        && CC="cc" CFLAGS="-O2 -fomit-frame-pointer -pipe " \
        ./configure --disable-shared 
/bin/sh: line 2: ./configure: 没有那个文件或目录
make[1]: *** [/home/redhat/tools/nginx/zzw_other/pcre-8.10/Makefile] 错误 127
make[1]: Leaving directory `/home/redhat/tools/nginx'
make: *** [build] 错误 2

        原因:
                --with-pcre=让你设置到源码目录,而不是编译安装后的目录。这点与apache的编译还有点不同。用./configure  -help 可以看配置参数帮助
        解决方案:
                修改 --with-pcre=后的路径为pcre的解压后的源路径

 

 

 

转载于:https://my.oschina.net/u/3375733/blog/1827778

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值