作业要求
配置nginx服务通过ip访问多网站
[root@localhost ~]# systemctl stop firewalled
Failed to stop firewalled.service: Unit firewalled.service not loaded.
[root@localhost ~]# mount /dev/sr0 /mnt
mount: /mnt: /dev/sr0 已挂载于 /run/media/redhat/RHEL-9-3-0-BaseOS-x86_64.
[root@localhost ~]# dnf install firewalld -y
正在更新 Subscription Management 软件仓库。
无法读取客户身份
本系统尚未在权利服务器中注册。可使用 subscription-manager 进行注册。
BaseOS 2.7 MB/s | 2.7 kB 00:00
AppStream 3.1 MB/s | 3.2 kB 00:00
软件包 firewalld-1.2.1-1.el9.noarch 已安装。
依赖关系解决。
无需任何处理。
完毕!
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost redhat]# dnf install nginx -y
正在更新 Subscription Management 软件仓库。
无法读取客户身份
本系统尚未在权利服务器中注册。可使用 subscription-manager 进行注册。
上次元数据过期检查:0:00:06 前,执行于 2024年10月20日 星期日 15时52分19秒。
依赖关系解决。
================================================================================
软件包 架构 版本 仓库 大小
================================================================================
安装:
nginx x86_64 1:1.20.1-14.el9_2.1 AppStream 40 k
安装依赖关系:
nginx-core x86_64 1:1.20.1-14.el9_2.1 AppStream 574 k
nginx-filesystem noarch 1:1.20.1-14.el9_2.1 AppStream 11 k
redhat-logos-httpd noarch 90.4-2.el9 AppStream 18 k
事务概要
================================================================================
安装 4 软件包
总计:643 k
安装大小:1.8 M
下载软件包:
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
准备中 : 1/1
运行脚本: nginx-filesystem-1:1.20.1-14.el9_2.1.noarch 1/4
安装 : nginx-filesystem-1:1.20.1-14.el9_2.1.noarch 1/4
安装 : nginx-core-1:1.20.1-14.el9_2.1.x86_64 2/4
安装 : redhat-logos-httpd-90.4-2.el9.noarch 3/4
安装 : nginx-1:1.20.1-14.el9_2.1.x86_64 4/4
运行脚本: nginx-1:1.20.1-14.el9_2.1.x86_64 4/4
验证 : nginx-1:1.20.1-14.el9_2.1.x86_64 1/4
验证 : nginx-core-1:1.20.1-14.el9_2.1.x86_64 2/4
验证 : nginx-filesystem-1:1.20.1-14.el9_2.1.noarch 3/4
验证 : redhat-logos-httpd-90.4-2.el9.noarch 4/4
已更新安装的产品。
已安装:
nginx-1:1.20.1-14.el9_2.1.x86_64
nginx-core-1:1.20.1-14.el9_2.1.x86_64
nginx-filesystem-1:1.20.1-14.el9_2.1.noarch
redhat-logos-httpd-90.4-2.el9.noarch
完毕!
[root@localhost ~]# systemctl start nginx
三个方法查看是否运行,看监听状态,看端口,看进程
[root@localhost ~]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 34433/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1060/sshd: /usr/sbi
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 34333/sshd: root@pt
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1058/cupsd
tcp6 0 0 :::80 :::* LISTEN 34433/nginx: master
tcp6 0 0 :::22 :::* LISTEN 1060/sshd: /usr/sbi
tcp6 0 0 ::1:631 :::* LISTEN 1058/cupsd
tcp6 0 0 ::1:6010 :::* LISTEN 34333/sshd: root@pt
udp 0 0 0.0.0.0:5353 0.0.0.0:* 862/avahi-daemon: r
udp 0 0 127.0.0.1:323 0.0.0.0:* 907/chronyd
udp 0 0 0.0.0.0:53587 0.0.0.0:* 862/avahi-daemon: r
udp6 0 0 :::5353 :::* 862/avahi-daemon: r
udp6 0 0 ::1:323 :::* 907/chronyd
udp6 0 0 :::43630 :::* 862/avahi-daemon: r
[root@localhost ~]# lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 34433 root 6u IPv4 71074 0t0 TCP *:http (LISTEN)
nginx 34433 root 7u IPv6 71075 0t0 TCP *:http (LISTEN)
nginx 34434 nginx 6u IPv4 71074 0t0 TCP *:http (LISTEN)
nginx 34434 nginx 7u IPv6 71075 0t0 TCP *:http (LISTEN)
nginx 34435 nginx 6u IPv4 71074 0t0 TCP *:http (LISTEN)
nginx 34435 nginx 7u IPv6 71075 0t0 TCP *:http (LISTEN)
[root@localhost ~]# ps -aux | grep nginx
root 34433 0.0 0.0 10052 948 ? Ss 17:06 0:00 nginx: master process /usr/sbin/nginx
nginx 34434 0.0 0.2 13940 5008 ? S 17:06 0:00 nginx: worker process
nginx 34435 0.0 0.2 13940 5008 ? S 17:06 0:00 nginx: worker process
root 34453 0.0 0.1 221680 2432 pts/1 R+ 17:12 0:00 grep --color=auto nginx
[root@localhost ~]# nmtui
[root@localhost ~]# nmcli connection modify ens160 ipv4.method manual ipv4.addresses 192.168.169.100/24 +ipv4.addresses 192.168.169.200/24 ipv4.gateway 192.168.169.2 ipv4.dns 192.168.169.2
[root@localhost ~]# nmcli connection up ens160
[C:\~]$ ssh 192.168.169.100:22
Connecting to 192.168.169.100:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Activate the web console with: systemctl enable --now cockpit.socket
Register this system with Red Hat Insights: insights-client --register
Create an account or view all your systems at https://red.ht/insights-dashboard
Last login: Tue Oct 22 17:00:32 2024 from 192.168.169.1
[root@localhost ~]# vim /etc/nginx/conf.d/test_ip.conf
[root@localhost ~]# vim /etc/nginx/conf.d/test_ip.conf
[root@localhost ~]# mkdir /test/{100,200} -pv
mkdir: 已创建目录 '/test'
mkdir: 已创建目录 '/test/100'
mkdir: 已创建目录 '/test/200'
[root@localhost ~]# echo this is 100 > /test/100/index.html
[root@localhost ~]# echo this is 200 > /test/200/index.html
[root@localhost ~]# systemctl restart nginx
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xeu nginx.service" for details.
[root@localhost ~]# vim /etc/nginx/conf.d/test_ip.conf
[root@localhost ~]# cat /etc/nginx/conf.d/test_ip.conf
server{
listen 192.168.169.100:80;
#server_name
root /test/100;
location /{
index index.html;
}
}
server{
listen 192.168.169.200:80;
#server_name
root /test/200;
location /{
index index.html;
}
}
[root@localhost ~]# systemctl restart nginx