1、下载Nginx安装包

快速下载:wgethttp://nginx.org/download/nginx-1.18.0.tar.gz

官网下载:http://nginx.org/en/download.html

Centos安装Nginx

2、安装相关依赖

安装或更新gcc-c++ 依赖

yum -y install gcc gcc-c++ autoconf automake make

否则在安装过程中会报错如下:

./configure: error: C compiler cc is not found

安装或更新pcre、openssl

yum -y install pcre-devel

yum -y install openssl openssl-devel

否则在安装过程中会报错如下:

./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 install -y zip unzip

3、解压Nginx安装包

# 解压到当前目录
tar zxvf nginx-1.18.0.tar.gz

4、配置安装运行目录

# 进入nginx解压目录下
cd /usr/local/nginx/nginx-1.18.0
# 配置安装运行命令
./configure --prefix=/usr/local/nginx/nginx

5、执行编译安装

make && make install

6、启动Nginx

# 进入到运行目录
cd /usr/local/nginx/nginx
# 启动Nginx并指定配置文件 -t 测试配置文件是否正确
./sbin/nginx -s stop -c conf/nginx.conf
# 停止Nginx -s quit(等待进程处理完毕进行关闭)
./sbin/nginx -s stop
# 重启
./sbin/nginx -s reload

默认监听80端口,访问测试即可

http://IP/

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。