创建目录
mkdir /usr/local/nginx
cd /usr/local/nginx
下载&解压
wget http://nginx.org/download/nginx-1.20.1.tar.gz
tar -xvf nginx-1.20.1.tar.gz
安装
cd nginx-1.20.1
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
可能报错
# 错误内容如下 个人理解为缺少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.
如果报错则先安装依赖
yum -y install make zlib-devel gcc-c++ libtool openssl openssl-devel
依赖解释 ↓↓↓↓↓↓↓↓↓
gcc(预处理、编译、连接、汇编)
openssl(用于网站加密通讯)
pcre(用于支持解析正则表达式)
zlib(对数据进行解压缩。网站间通信时,数据先压缩再传输,节省网络带宽)
重新执行
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
等待一顿刷频。。。。。。 会多出来个Makefile
安装
make;
make install;
回到安装目录
cd ..
#或者
cd /usr/local/nginx/sbin
#启动
./nginx
检查
ps -ef | grep nginx
开启端口(云服务器需要去管理后台开启端口安全组)
#Nginx 默认监听80端口 可自行配置
firewall-cmd --zone=public --add-port=你的端口/tcp --permanent
#重启防火墙
firewall-cmd --reload
#打开你的浏览器访问你的IP地址即可