文章时间:2019年12月17日 11:08:08
解决问题:Linux系统非root用户安装及配置Nginx
基于系统:RedHat CentOS
这里我没研究非root用户安装(因为太麻烦了),后面我会单独出一篇文章,讲解非root用户安装gcc编译器。
直接使用su -
切换到root用户下面,使用yum安装gcc。
yum install -y gcc-c++
wget https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz
tar zxvf pcre-8.43.tar.gz
cd pcre-8.43
./configure --prefix=/home/oper/soft/pcre-8.43 --enable-utf8
这里使用wget命令下载的,如果你也像我一样,是个纯内网的,那么,请到文章底部,直接下载我下载好的包吧。
wget http://zlib.net/zlib-1.2.11.tar.gz
tar zxvf zlib-1.2.11.tar.gz
wget https://www.openssl.org/source/openssl-1.0.2s.tar.gz
tar zxvf openssl-1.0.2s.tar.gz
wget http://nginx.org/download/nginx-1.16.1.tar.gz
tar zxvf nginx-1.16.1.tar.gz
cd nginx-1.16.1
./configure \
--prefix=../nginx \
--with-pcre=../pcre-8.43 \
--with-zlib=../zlib-1.2.11 \
--with-openssl=../openssl-1.0.2t \
--user=root \
--group=root \
--with-file-aio \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_sub_module \
--with-http_gzip_static_module \
--with-http_stub_status_module
说明:如果你能看懂上面的,你就看懂,如果看不懂,你就复制粘贴运行。
--prefix=../nginx \
这里可以写成你的绝对路径。
make install
执行完上面的命令,这里可能会报如下错误。
make -f objs/Makefile install
make[1]: Entering directory `/home/oper/soft/nginx-1.18.0'
cd ../pcre-8.43 \
&& if [ -f Makefile ]; then make distclean; fi \
&& CC="cc" CFLAGS="-O2 -fomit-frame-pointer -pipe " \
./configure --disable-shared
/bin/sh: line 2: ./configure: Permission denied
make[1]: *** [../pcre-8.43/Makefile] Error 126
make[1]: Leaving directory `/home/oper/soft/nginx-1.18.0'
make: *** [install] Error 2
这里可以看出是因为权限导致出现的问题,那我来执行命令,加权限chmod +x ./configure
输入完之后回车发现又报错了。
chmod: changing permissions of ‘./configure’: Operation not permitted
这里提示的还是权限不足,这是我们强行用root用户给加权限能行的通。方法有很多种。
这里的报错集中在pcre上面,请跳转pcre安装及报错详解。解决完pcre在继续安装nginx。
非root用户运行nginx不能监听1024以下的端口号。所以我们需要如下的操作:
需要root用户cd到sbin目录中设权限
chown root:root nginx
chmod 755 nginx
chmod u+s nginx
/nginx/sbin/nginx
输入上面的命令即可正常启动nginx。
# 检查配置文件
/nginx/sbin/nginx -t
# 重启nginx
/nginx/sbin/nginx -s reload
这里启动之后,还会碰到一个问题,就是外网访问ip或者配置好的域名,发现无法文档通的情况。
这个时候一般问题有如下几个:(已经碰到过的,还有其他情况有待补充)
防火墙开通的方法教程:https://wiki.nooss.cn/archives/49.html
https://blog.csdn.net/hursing/article/details/93860565
https://www.cnblogs.com/zzw-zyba/p/8820160.html
https://blog.csdn.net/sweeneil/article/details/103237214
链接: https://pan.baidu.com/s/1llum2N419M1ed9MkUVRXiA 提取码: zhia