一、安装环境:
[root@red3212 ~]# cat /etc/redhat-release
CentOS Linux release 8.3.2011
[root@red3212 ~]# ifconfig ens32
ens32: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.18.18 netmask 255.255.255.0 broadcast 192.168.18.255
inet6 fe80::f111:5242:40bc:7744 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:80:10:f3 txqueuelen 1000 (Ethernet)
RX packets 743288 bytes 1100903837 (1.0 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 220212 bytes 17136089 (16.3 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
二、安装过程:
第1步:安装工具包
[root@red3212 ~]# dnf -y install gcc gcc-c++ automake openssl-devel zlib-devel zlib pcre-devel autoconf cmake
第2步:创建用户账号
[root@red3212 ~]# groupadd -g 1001 nginx
[root@red3212 ~]# useradd -u 900 nginx -g nginx -s /sbin/nologin
[root@red3212 ~]# tail -1 /etc/passwd
nginx:x:900:1001::/home/nginx:/sbin/nologin
第3步:安装nginx服务程序
[root@red3212 ~]# wget http://nginx.org/download/nginx-1.21.5.tar.gz
[root@red3212 ~]# tar -xzvf nginx-1.21.5.tar.gz
[root@red3212 ~]# cd nginx-1.21.5
[root@red3212 nginx-1.21.5]# ./configure \
--prefix=/usr/local/nginx \
--with-http_dav_module \
--with-http_stub_status_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_ssl_module \
--with-http_gzip_static_module \
--user=nginx \
--group=nginx
如果没有报错,则进行下一步安装
[root@red3212 nginx-1.21.5]# make && make install
第4步:创建软链接并启动测试
[root@red3212 nginx-1.21.5]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
[root@red3212 nginx-1.21.5]# nginx -t
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@red3212 nginx-1.21.5]# nginx
[root@red3212 nginx-1.21.5]# netstat -ntlp | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 40871/nginx: master
如果看到80端口启动,则表示nginx服务启动成功。
第5步:设置防火墙
虽然可以执行命令systemctl stop firewalld直接关闭防火墙,但不建议这样操作。
建议设置防火墙规则,在public区域中添加http服务
[root@red3212 nginx-1.21.5]# firewall-cmd --permanent --zone=public --add-service=http
success
[root@red3212 nginx-1.21.5]# firewall-cmd --reload
success
第6步:浏览测试
在另一台可以与nginx服务器网络相通的主机上(如宿主主机)开启浏览器,访问nginx服务器的IP,如下图所示,若能打开如下图所示的页面,则表示配置成功。