Linux centos7 安装nginx

文章封面

安装前准备 安装GCC编译环境

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

安装模块依赖

Nginx支持的功能模块需要有第三方的库支持,例如gzip的zlib库,rewrite重写需要的pcre库,HTTPS需要的openssl库等等。

yum install zlib zlib-devel openssl openssl-devel pcre pcre-devel wget httpd-tools vim -y --setopt=protected_multilib=false

下载安装包 上传安装包至/usr/local,nginxhttp://nginx.org/en/download.html下载地址,本次使用的nginx-1.20.2

tar -zxf nginx-1.20.2.tar.gz

让vim系统识别Nginx语法

[root@localhost nginx]# cd nginx-1.20.2/ [root@localhost nginx-1.20.2]# mkdir ~/.vim [root@localhost nginx-1.20.2]# cp -r contrib/vim/* ~/.vim/

编译安装三部曲 编译Nginx,扩展编译模块

./configure --prefix=/opt/Nginx1.20.2/ --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --with-http_stub_status_module --with-threads --with-file-aio

--prefix=/opt/Nginx1.20.2/ 是安装目录位置

执行make,进行编译

make

make install 进行安装

make install

配置Nginx环境变量 创建系统服务

echo export PATH=/opt/Nginx1.22/sbin:$PATH > /etc/profile.d/nginx.sh

重新登录终端,查看环境变量

echo $PATH

检查nginx版本和安装模块

nginx -V

nginx 启动

nginx执行文件在安装目录下的sbin里

6a29b098ef4830d66ae1906f242ca83

这样子就安装完成了,大家可以多多进行尝试,缺乏机器与环境的话可以去 3A 服务器看看!

评论

暂无评论