centos7下载安装nginx

发布时间 2023-11-22 14:03:20作者: 俟礼

一、下载准备工作

Nginx安装版本:nginx-1.24.0.tar.gz

Linux环境:先执行这个

yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel

二、安装nginx

1、把nginx安装包放到/data/nginx下

cd /data/nginx

wget http://nginx.org/download/nginx-1.24.0.tar.gz

2、解压安装包:

tar -xvf nginx-1.24.0.tar.gz

3、可以考虑修改安装包名称:

ls
#改名
mv nginx-1.8.1 nginx

4、进入nginx目录:

cd nginx-1.24.0

5、配置 执行

./configure --prefix=/data/nginx/nginx-1.24.0 --conf-path=/data/nginx/nginx-1.24.0/nginx.conf

6、编译安装

make && make install

三、验证是否安装成功

1、在/data/nginx/nginx-1.24.0/sbin目录执行./nginx 启动nginx

cd sbin
./nginx

修改配置后执行这条命令:

/data/nginx/nginx-1.24.0/sbin/nginx -c /data/nginx/nginx-1.24.0/conf/nginx.conf  

2.在浏览器中输入http://ip:80出现如下界面,表示启动成功
image

四、安装中遇到的问题

1、问题1,执行./configure报错

./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.

解决办法:

执行:yum -y install pcre-devel命令即可

2、

执行./configure报错

./configure: error: the HTTP gzip module requires the zlib library.
-------------------------------------------------------------------
You can either disable the module by using --without-http_gzip_module

option, or install the zlib library into the system, or build the zlib library

statically from the source with nginx by using --with-zlib=<path> option.

执行yum -y install zlib-devel

3、./nginx 重启时报错

 nginx: [alert] could not open error log file: open() "/data/nginx/nginx-1.24.0/logs/error.log" failed (2: No such file or directory)

解决方法:

提示没有这个文件,是因为在nginx目录下没有logs文件夹,创建一个在启动即可

cd /data/nginx/nginx-1.24.0

mkdir logs

cd sbin

./nginx

4、目录为同一级

make[1]: Leaving directory `/data/nginx/nginx-1.24.0'

make -f objs/Makefile install

make[1]: Entering directory `/data/nginx/nginx-1.24.0'

test -d '/data/nginx/nginx-1.24.0' || mkdir -p '/data/nginx/nginx-1.24.0'

test -d '/data/nginx/nginx-1.24.0/sbin' || mkdir -p '/data/nginx/nginx-1.24.0/sbin'

test ! -f '/data/nginx/nginx-1.24.0/sbin/nginx' || mv '/data/nginx/nginx-1.24.0/sbin/nginx' '/data/nginx/nginx-1.24.0/sbin/nginx.old'

cp objs/nginx '/data/nginx/nginx-1.24.0/sbin/nginx'

test -d '/data/nginx/nginx-1.24.0/conf' || mkdir -p '/data/nginx/nginx-1.24.0/conf'

cp conf/koi-win '/data/nginx/nginx-1.24.0/conf'

cp: "conf/koi-win" 与"/data/nginx/nginx-1.24.0/conf/koi-win" 为同一文件

make[1]: *** [install] 错误 1

make[1]: Leaving directory `/data/nginx/nginx-1.24.0'

make: *** [install] 错误 2

这是因为编译安装过一次,再次编译安装时,sbin等文件夹已经存在所以会包这个错误,可以删除该文件夹再次安装,或者忽略该错误

5、

nginx: [error] invalid PID number "" in "/data/nginx/nginx-1.24.0/logs/nginx.pid"

使用/data/nginx/nginx-1.24.0/sbin/nginx -s reload 重新读取配置文件出错


[root@localhost nginx]/data/nginx/nginx-1.24.0/sbin/nginx -s reload

提示 nginx: [error] invalid PID number "" in "/data/nginx/nginx-1.24.0/logs/nginx.pid"

 

[root@localhost nginx]# cd logs

[root@localhost logs]# ls

access.log error.log nginx-access.log nginx_error.log

果然没有/data/nginx/nginx-1.24.0/logs/nginx.pid 文件

解决方法:用指定文件加载nginx配置文件

[root@localhost nginx]/data/nginx/nginx-1.24.0/sbin/nginx -c /data/nginx/nginx-1.24.0/conf/nginx.conf

搞定!!!