CentOS Stream 9(十)远程访问80端口 日期:2023-11-28 人气:453 在CognizeX:CentOS Stream 9(七)httpd中,我们开启了http服务,并且可以CentOS Stream 9本机,通过访问127.0.0.1或localhost,打开默认网页。 如果我们想远程访问这个网页,可以吗? 比如,我们在主机浏览器直接访问这个虚拟机的ip:192.168.56.101,会发现打不开网页。 查看httpd状态 ``` [adminuser@localhost ~]$ systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; preset: disabled) Active: active (running) since Wed 2023-04-19 11:44:07 CST; 14min ago Docs: man:httpd.service(8) Main PID: 3306 (httpd) Status: "Total requests: 1; Idle/Busy workers 100/0;Requests/sec: 0.00116; Bytes served/sec: 530 B/sec" Tasks: 214 (limit: 10981) Memory: 20.4M CPU: 733ms CGroup: /system.slice/httpd.service ├─3306 /usr/sbin/httpd -DFOREGROUND ├─3318 /usr/sbin/httpd -DFOREGROUND ├─3319 /usr/sbin/httpd -DFOREGROUND ├─3320 /usr/sbin/httpd -DFOREGROUND ├─3324 /usr/sbin/httpd -DFOREGROUND └─3325 /usr/sbin/httpd -DFOREGROUND 4月 19 11:44:05 localhost.localdomain systemd[1]: Starting The Apache HTTP Server... 4月 19 11:44:06 localhost.localdomain httpd[3306]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally > 4月 19 11:44:07 localhost.localdomain httpd[3306]: Server configured, listening on: port 443, port 80 4月 19 11:44:07 localhost.localdomain systemd[1]: Started The Apache HTTP Server. ``` httpd服务已经启动。 ``` httpd.service - The Apache HTTP Server Active: active (running) ``` 原因是:默认情况下,CentOS Stream 9的防火墙没有打开80端口的远程访问。 查看防火墙状态 ``` [adminuser@localhost ~]$ systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; preset: enabled) Active: active (running) since Wed 2023-04-19 11:07:51 CST; 51min ago Docs: man:firewalld(1) Main PID: 839 (firewalld) Tasks: 2 (limit: 10981) Memory: 15.3M CPU: 1.149s CGroup: /system.slice/firewalld.service └─839 /usr/bin/python3 -s /usr/sbin/firewalld --nofork --nopid 4月 19 11:07:42 localhost systemd[1]: Starting firewalld - dynamic firewall daemon... 4月 19 11:07:51 localhost systemd[1]: Started firewalld - dynamic firewall daemon. ``` 有很多教程,让大家关闭防火墙,然后就可以远程访问了,这个做法不厚道啊。 下面我们来看一下,如何设置防火墙,打开80端口的远程访问权限。 首先看一下,防火墙已经开放的端口: ``` [adminuser@localhost ~]$ firewall-cmd --list-port ``` 没有开放任何端口(所以不能远程访问80端口)。 添加开放80端口 ``` [adminuser@localhost ~]$ firewall-cmd --zone=public --add-port=80/tcp --permanent success ``` 重启防火墙 ``` [adminuser@localhost ~]$ firewall-cmd --reload success ``` 再次查看防火墙已经开放的端口: ``` [adminuser@localhost ~]$ sudo firewall-cmd --list-port 80/tcp ``` 远程访问,试一下 ### 鸣谢 - [知乎**CognizeX**](https://zhuanlan.zhihu.com/p/623132590) 标签: 80 防火墙 http 上一篇:vscode使用Community Server Connector运行JDK1.8项目报错 下一篇:gitlab修改默认nginx端口号 随便看看 2025-07-04 vscode使用Community Server Connector运行JDK1.8项目报错 2025-07-03 vscode中为maven项目指定java版本 2025-06-27 利用puppeteer将网页保存为pdf 2025-06-27 一天二十四时辰表 2025-06-27 家谱中儿子和父母的关系有哪些? 留言