安装httpd服务并配置

1、安装httpd服务

# yum install httpd -y

2、开启httpd服务

# systemctl start httpd

查看状态

# systemctl status httpd

[root@localhost ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since 六 2021-08-07 23:47:07 CST; 4s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 2691 (httpd)
   Status: "Processing requests..."
   CGroup: /system.slice/httpd.service
           ├─2691 /usr/sbin/httpd -DFOREGROUND
           ├─2692 /usr/sbin/httpd -DFOREGROUND
           ├─2693 /usr/sbin/httpd -DFOREGROUND
           ├─2694 /usr/sbin/httpd -DFOREGROUND
           ├─2695 /usr/sbin/httpd -DFOREGROUND
           └─2696 /usr/sbin/httpd -DFOREGROUND

8月 07 23:47:06 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
8月 07 23:47:07 localhost.localdomain httpd[2691]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using l... message
8月 07 23:47:07 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.

3、防火墙开放端口

临时开放端口

# firewall-cmd --add-service=http

[root@localhost ~]# firewall-cmd --add-service=http
success

4、浏览器测试访问

访问地址如下:

http://虚机的IP地址/

5、配置httpd服务

httpd服务配置文件的存放位置路径如下:

/etc/httpd/conf.d/

这个路径下,凡事以.conf文件结尾的,都是httpd的配置文件。

在浏览器访问测试页面的时候,http服务实际会读取

/etc/httpd/conf.d/welcome.conf文件

此文件用于配置浏览器访问的测试页面。

6、自己写一个测试页面,用于浏览器访问。

切换到httpd服务默认读取前端代码文件的路径中

# cd /var/www/html/

编写一个index页面

# vi index.html

此index.hrml的配置内容简略如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dong Ying Technology University</title>
</head>
<body>
    <h1>welcome to dongying technology university</h1>
    <p>This school is a new one!</p>
</body>
</html>

7、返回浏览器刷新页面查看效果。

原文地址:https://www.cnblogs.com/djlsunshine/p/9629806.html