参考文章:https://www.runoob.com/linux/nginx-install-setup.html
1.安装编译工具
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
2.下载PCRE
[root@ecs-69638 src]# cd /usr/local/src/
[root@ecs-69638 src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
3.解压安装PCRE
[root@ecs-69638 src]# tar zxvf pcre-8.35.tar.gz
[root@ecs-69638 src]# cd pcre-8.35
[root@ecs-69638 pcre-8.35]# ./configure
[root@ecs-69638 pcre-8.35]# make && make install
4.安装Nginx
[root@ecs-69638 usr]# cd /usr/local/src/
[root@ecs-69638 src]# wget http://nginx.org/download/nginx-1.21.5.tar.gz
[root@ecs-69638 src]# tar zxvf nginx-1.21.5.tar.gz
[root@ecs-69638 src]# cd nginx-1.21.5
[root@ecs-69638 nginx-1.21.5]# ./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
[root@ecs-69638 nginx-1.21.5]# make && make install
如果编译出现错误,可能是把警告作为异常抛出了,到
/usr/local/src/nginx-1.6.2/objs/Makefile
删除-Werror
5.配置Nginx
[root@ecs-69638 nginx-1.21.5]# cat /usr/local/webserver/nginx/conf/nginx.conf
# 修改配置
[root@ecs-69638 nginx-1.21.5]# cd /usr/local/webserver/nginx/conf/
[root@ecs-69638 conf]# vim nginx.conf
6.启动Nginx
[root@ecs-69638 conf]# /usr/local/webserver/nginx/sbin/nginx -t
其他命令:
/usr/local/webserver/nginx/sbin/nginx -s reload # 重新载入配置文件
/usr/local/webserver/nginx/sbin/nginx -s reopen # 重启 Nginx
/usr/local/webserver/nginx/sbin/nginx -s stop # 停止 Nginx
注意:配置以及启动前要先配置安全组规则,开放对应的端口,否则可能无法访问