HTTP服务器搭建

article/2025/9/18 21:06:02

文章目录

  • 实验环境说明
  • 服务器配置
    • 下载安装HTTP服务
    • 修改配置文件
  • 客户端测试
    • Linux客户端测试
    • Windows客户端测试


实验环境说明

主机系统系统版本IP地址
服务端LinuxRHEL 7.0192.168.43.128/24
客户端LinuxRHEL 7.4192.168.43.15/24
客户端Windows 11Windows 11192.168.43.1/24
  • 基本环境配置参考【DHCP服务搭建】和【Samba服务搭建】
    • IP地址配置
    • YUM仓库配置
    • 防火墙、SELinux配置

服务器配置

下载安装HTTP服务

  • 下载安装Apache
[root@Server ~]# yum -y install httpd
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Base                                                  | 4.1 kB     00:00     
(1/2): Base/group_gz                                    | 137 kB   00:00     
(2/2): Base/primary_db                                  | 4.0 MB   00:00     
Resolving Dependencies...Installed:httpd.x86_64 0:2.4.6-67.el7                                                Dependency Installed:apr.x86_64 0:1.4.8-3.el7                apr-util.x86_64 0:1.5.2-6.el7      httpd-tools.x86_64 0:2.4.6-67.el7       mailcap.noarch 0:2.1.41-2.el7      Complete!
[root@Server ~]# 
  • 防火墙放行HTTP服务
[root@Server conf]# firewall-cmd --list-all
public (default, active)interfaces: eno16777736sources: services: dhcp dhcpv6-client samba sshports: masquerade: noforward-ports: icmp-blocks: rich rules: [root@Server conf]# firewall-cmd --permanent --add-service="http"  //防火墙放行服务
success
[root@Server conf]# firewall-cmd --reload   //重新加载防火墙规则
success
[root@Server conf]# firewall-cmd --list-all  //列出防火墙的放行列表
public (default, active)interfaces: eno16777736sources: services: dhcp dhcpv6-client http samba sshports: masquerade: noforward-ports: icmp-blocks: rich rules: [root@Server conf]# 
  • 设置HTTP服务开机自启并启动HTTP服务
[root@Server conf]# systemctl enable httpd  //设置开机自启动
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'
[root@Server conf]# systemctl restart httpd  //重新启动HTTP服务
[root@Server conf]# systemctl status httpd  //查看HTTP服务状态
httpd.service - The Apache HTTP ServerLoaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)Active: active (running) since Fri 2021-12-24 10:31:41 CST; 10s agoDocs: man:httpd(8)man:apachectl(8)Process: 5230 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)Main PID: 5274 (httpd)Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"CGroup: /system.slice/httpd.service├─5274 /usr/sbin/httpd -DFOREGROUND├─5275 /usr/sbin/httpd -DFOREGROUND├─5276 /usr/sbin/httpd -DFOREGROUND├─5277 /usr/sbin/httpd -DFOREGROUND├─5278 /usr/sbin/httpd -DFOREGROUND└─5279 /usr/sbin/httpd -DFOREGROUNDDec 24 10:31:21 Server systemd[1]: Starting The Apache HTTP Server...
Dec 24 10:31:31 Server httpd[5274]: AH00557: httpd: apr_sockaddr_info_ge...er
Dec 24 10:31:31 Server httpd[5274]: AH00558: httpd: Could not reliably d...ge
Dec 24 10:31:41 Server systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@Server conf]# 
  • 在客户端进行访问测试
    • 如果没有安装图形化界面,可以使用命令curl 192.168.43.128来进行访问
    • 如果安装了图形化界面,则可以直接通过服务器的IP地址进行访问
[root@Server conf]# curl 192.168.43.128
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><title>Test Page for the Apache HTTP Server on Red Hat Enterprise Linux</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><style type="text/css">/*<![CDATA[*/....<div class="content-columns"><div class="content-column-left"><h2>If you are a member of the general public:</h2><p>The fact that you are seeing this page indicates that the website you just visited is either experiencing problems, or is undergoing routine maintenance.</p><p>If you would like to let the administrators of this website know that you've seen this page instead of the page you expected, you should send them e-mail. In general, mail sent to the name "webmaster" and directed to the website's domain should reach the appropriate person.</p><p>For example, if you experienced problems while visiting www.example.com, you should send e-mail to "webmaster@example.com".</p><p>For information on Red Hat Enterprise Linux, please visit the <a href="http://www.redhat.com/">Red Hat, Inc. website</a>. The documentation for Red Hat Enterprise Linux is <a href="http://www.redhat.com/docs/manuals/enterprise/">available on the Red Hat, Inc. website</a>.</p><hr /></div><div class="content-column-right"><h2>If you are the website administrator:</h2><p>You may now add content to the directory <tt>/var/www/html/</tt>. Note that until you do so, people visiting your website will see this page, and not your content. To prevent this page from ever being used, follow the instructions in the file <tt>/etc/httpd/conf.d/welcome.conf</tt>.</p><p>You are free to use the image below on web sites powered by the Apache HTTP Server:</p><p align="center"><a href="http://httpd.apache.org/"><img src="/icons/apache_pb2.gif" alt="[ Powered by Apache ]"/></a></p></div></div></div></body>
</html>

请添加图片描述

  • 可以看到以上界面(默认界面),则说明HTTP服务已经安装成功,接下来需要修改配置文件

修改配置文件

  • 修改网页头文件路径
[root@Server ~]# cd /etc/httpd/conf/
[root@Server conf]# mv httpd.conf httpd.conf.bak   //将配置文件做备份
[root@Server conf]# cat httpd.conf.bak | grep -v "#" | grep -v "^$" > httpd.conf
[root@Server conf]# vim httpd.conf
ServerRoot "/etc/httpd"Listen 80  //HTTP服务端口Include conf.modules.d/*.confUser apache
Group apacheServerAdmin root@localhost<Directory />AllowOverride noneRequire all denied#DocumentRoot "/var/www/html"
DocumentRoot "/var/www/Bad"  //网页头文件位置...[root@Server conf]# cd /var/www
[root@Server www]# mkdir Bad
  • 运行虚拟主机配置
[root@Server www]# rpm -ql httpd | grep vhosts  //查看虚拟主机软件包
/usr/share/doc/httpd-2.4.6/httpd-vhosts.conf
[root@Server www]# cp /usr/share//doc/httpd-2.4.6/httpd-vhosts.conf /etc/httpd/conf
[root@Server www]# cd /etc/httpd/conf
[root@Server conf]# ls
httpd.conf  httpd.conf.bak  httpd-vhosts.conf  magic
[root@Server conf]# mv httpd-vhosts.conf httpd-vhosts.conf.bak
[root@Server conf]# cat httpd-vhosts.conf.bak | grep -v "#" > httpd-vhosts.conf
[root@Server conf]# vim httpd-vhosts.conf
[root@Server conf]# vim httpd-vhosts.conf
#<VirtualHost *:@@Port@@>
#    ServerAdmin webmaster@dummy-host.example.com
#    DocumentRoot "@@ServerRoot@@/docs/dummy-host.example.com"
#    ServerName dummy-host.example.com
#    ServerAlias www.dummy-host.example.com
#    ErrorLog "/var/log/httpd/dummy-host.example.com-error_log"
#    CustomLog "/var/log/httpd/dummy-host.example.com-access_log" common
#</VirtualHost><VirtualHost www.bad.boy.com>      //配置虚拟域名,也可以配置为访问端口DocumentRoot /var/www/Bad      //网页头文件的目录ServerName www.bad.boy.com     //域名地址
</VirtualHost>
[root@Server conf]#
  • 将网页文件通过Xftp或其他远程软件上传至服务器的/var/www/Bad目录下
    请添加图片描述
  • 重新启动HTTP服务
[root@Server ~]# systemctl restart httpd
[root@Server ~]# systemctl status httpd
httpd.service - The Apache HTTP ServerLoaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)Active: active (running) since Fri 2021-12-24 12:21:50 CST; 29s agoDocs: man:httpd(8)man:apachectl(8)Process: 8406 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)Main PID: 8410 (httpd)Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"CGroup: /system.slice/httpd.service├─8410 /usr/sbin/httpd -DFOREGROUND├─8411 /usr/sbin/httpd -DFOREGROUND├─8412 /usr/sbin/httpd -DFOREGROUND├─8413 /usr/sbin/httpd -DFOREGROUND├─8414 /usr/sbin/httpd -DFOREGROUND└─8415 /usr/sbin/httpd -DFOREGROUNDDec 24 12:21:30 Server systemd[1]: Starting The Apache HTTP Server...
Dec 24 12:21:40 Server httpd[8410]: AH00557: httpd: apr_sockaddr_info_ge...er
Dec 24 12:21:40 Server httpd[8410]: AH00558: httpd: Could not reliably d...ge
Dec 24 12:21:50 Server systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@Server ~]#

客户端测试

Linux客户端测试

  • 使用IP地址进行访问测试
    请添加图片描述
  • 使用域名进行访问测试请添加图片描述
  • 会出现无法访问的提示,这是因为客户端无法解析www.bad.boy.com这个域名,因为还没有搭建【DNS服务器】解析域名,所以需要做一个本地映射,将域名映射为服务器的IP地址
  • Linux客户端配置本地映射
[root@Client ~]# vim /etc/hosts
[root@Client ~]# tail -1 /etc/hosts
192.168.43.128 www.bad.boy.com
[root@Client ~]#
  • 重新使用域名在Linux客户端进行访问测试
    请添加图片描述

Windows客户端测试

  • 使用IP进行访问测试
    请添加图片描述
  • 直接使用域名访问,也会出现无法访问的错误
  • 在Windows客户端同样也需要修改IP与域名的映射关系才能正常使用域名进行访问
    • 在主机的C:\Windows\System32\drivers\etc目录下,将hosts移动到桌面上,进行修改,添加192.168.43.128 www.bad.boy.com保存
      请添加图片描述
  • 重新使用域名在Windows客户端进行访问测试
    请添加图片描述
  • HTTP基本配置完成,另外也可以修改HTTP的访问端口,可以使用IP/域名+端口号进行访问。其他详细的配置,可以参考帮助手册。

以上内容均属原创,如有不详或错误,敬请指出。

http://chatgpt.dhexx.cn/article/2OU70iNS.shtml

相关文章

WEB/HTTP服务器搭建

HTTP 对于软件都有服务和客户&#xff0c;有服务端和客户端 服务 就是在操作系统运行一个或者多个程序&#xff0c;并为客户端提供相应所需的服务 协议 就是计算机网络中进行数据交换而建立的规则、标准或约定的集合。只有遵守这个约定&#xff0c;计算机之间才能相互通信…

ESP32基础应用之HTTP 服务器

文章目录 1 HTTP服务器简介2 ApiPost测试工具3 HTTP服务器实验3.1 ApiPost之GET测试3.2 ApiPost之POST测试3.3 ApiPost值PUT测试 参考资料&#xff1a; esp32 http服务器编程指南 1 HTTP服务器简介 HTTP服务器一般指Web服务器&#xff0c;是指驻留于因特网上某种类型计算机的…

http 服务器搭建

目录 http 服务器搭建有很多条数据时用response.write测试服务器是否开启 http 服务器搭建 通过http模块提供的方法可以创建服务器 1 引入http模块 &#xff08;nodejs内置模块&#xff0c; 可以直接引入&#xff09; const http require(http);创建服务器http.createServer…

HTTP服务器(一)HTTP服务器入门介绍

一、简介 1.1、做项目的时候&#xff0c;要请求REST服务器。而FEST服务器还是用http基本原理(即阉割版)来请求。 1.2、请求端口EndPoint/请求方法Method/请求内容格式ContentType/请求的数类型PostData(一般为JSon格式)。 1.3、我们熟悉的HTTP、FTP、Telnet等协议都是建立在…

【八】http服务器开发--实现一个http服务器

文章目录 一、整体概述二、接收http请求三、响应http请求四、完整代码即效果4.1 完整代码&#xff1a;4.2 实现过程 附&#xff08;stat函数&#xff09; 一、整体概述 本节主要实现一个http服务器的示例&#xff1b;该http服务器的主要功能是&#xff0c;在浏览器端访问服务器…

蓝桥杯c语言基础试题答案,试题 基础练习 Huffuman树 蓝桥杯 C语言

资源限制 时间限制&#xff1a;1.0s 内存限制&#xff1a;512.0MB 问题描述 Huffman树在编码中有着广泛的应用。在这里&#xff0c;我们只关心Huffman树的构造过程。 给出一列数{pi}{p0, p1, …, pn-1}&#xff0c;用这列数构造Huffman树的过程如下&#xff1a; 1. 找到{pi}中最…

蓝桥杯基础试题 字母图形 C语言实现

资源限制 时间限制&#xff1a;1.0s 内存限制&#xff1a;256.0MB 问题描述 利用字母可以组成一些美丽的图形&#xff0c;下面给出了一个例子&#xff1a; ABCDEFG BABCDEF CBABCDE DCBABCD EDCBABC 这是一个5行7列的图形&#xff0c;请找出这个图形的规律&#xff0c…

蓝桥杯c语言b组试题及答案,2014蓝桥杯C语言本科B组预赛试题

2014蓝桥杯C语言本科B组预赛试题 2014 蓝桥杯 C/C语言本科 B 组预赛试题12014 蓝桥杯 C/C语言本科 B 组预赛试题(完整)1.啤酒和饮料啤酒每罐 2.3 元&#xff0c;饮料每罐 1.9 元。小明买了若干啤酒和饮料&#xff0c;一共花了 82.3 元。我们还知道他买的啤酒比饮料的数量少&am…

2018年蓝桥杯C语言B组

第一题 标题&#xff1a;第几天 2000年的1月1日&#xff0c;是那一年的第1天。 那么&#xff0c;2000年的5月4日&#xff0c;是那一年的第几天&#xff1f; 注意&#xff1a;需要提交的是一个整数&#xff0c;不要填写任何多余内容 第二题 标题&#xff1a;明码 汉字的字…

(求救大佬)蓝桥杯C语言试题 算法训练 C++ CH08 01

题目&#xff1a; 求解我的代码有什么问题&#xff0c;为什么不能通过蓝桥的编译&#xff0c;但运行结果都正确。 我的代码&#xff1a; #include<stdio.h> int main() { double ssh,zrf,y,x,g,f; int a,b,c,d,t,x1,x2,x3,x4,q; int i,j; scanf("%d%d%d%d",&a…

蓝桥杯训练题C语言

开学后就很少抽空写写题了&#xff0c;所以这次只有几道题目和大家分享一下了。 有些真题也有些VIP基础题&#xff0c;想和大家分享一下。&#xff08;有些是仿的其他博主的代码&#xff0c;&#xff0c;&#xff0c;&#xff0c;因为有些确实难&#xff08;呜呜呜~&#xff0…

蓝桥杯研究生c语言试题答案,蓝桥杯试题C语言答案.doc

蓝桥杯试题C语言答案.doc 下载提示(请认真阅读)1.请仔细阅读文档&#xff0c;确保文档完整性&#xff0c;对于不预览、不比对内容而直接下载带来的问题本站不予受理。 2.下载的文档&#xff0c;不会出现我们的网址水印。 3、该文档所得收入(下载内容预览)归上传者、原创作者&am…

蓝桥杯 C语言 试题 历届试题 格子刷油漆

试题 历届试题 格子刷油漆 问题描述   X国的一段古城墙的顶端可以看成 2*N个格子组成的矩形&#xff08;如下图所示&#xff09;&#xff0c;现需要把这些格子刷上保护漆。 你可以从任意一个格子刷起&#xff0c;刷完一格&#xff0c;可以移动到和它相邻的格子&#xff08;…

蓝桥杯 C语言 试题 历届试题 网络寻路

试题 历届试题 网络寻路 问题描述 X 国的一个网络使用若干条线路连接若干个节点。节点间的通信是双向的。某重要数据包&#xff0c;为了安全起见&#xff0c;必须恰好被转发两次到达目的地。该包可能在任意一个节点产生&#xff0c;我们需要知道该网络中一共有多少种不同的转发…

蓝桥杯 C语言 试题 算法训练 审美课

试题 算法训练 审美课 问题描述   《审美的历程》课上有n位学生&#xff0c;帅老师展示了m幅画&#xff0c;其中有些是梵高的作品&#xff0c;另外的都出自五岁小朋友之手。老师请同学们分辨哪些画的作者是梵高&#xff0c;但是老师自己并没有答案&#xff0c;因为这些画看上…

C语言课程设计——25道蓝桥杯练习题

文章目录 一、基础练习1.fib数列题目解题思路解题代码解法一(简单递推)&#xff1a;时间复杂度O(n)解法二(矩阵快速幂)&#xff1a;时间复杂度O(logn) 2.闰年判断题目解题思路解题代码 3. 数列特征题目解题思路解题代码 4.查找整数题目解题思路解题代码解法一&#xff1a;C风格…

蓝桥杯C语言程序设计真题

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 前言一、真题总结 前言 下面是蓝桥杯历年的真题希望对大家有用 一、真题 1&#xff0c;隔行变色 Excel表的格子很多&#xff0c;为了避免把某行的数据和相邻行混…

2022年第十三届蓝桥杯大赛C组真题C/C++解析(上)

**今天给大家带来2022年&#xff0c;第十三届蓝桥杯大赛的真题解析**转眼间&#xff0c;距离考试已经过去很长时间了&#xff0c;今天解元给大家解析一下&#xff0c;有问题欢迎大家指点 :笑: 下面进入正题 前言填空题1.排列字母2.特殊时间 编程题1.纸张尺寸1.1纸张大小代码 2.…

pthread+Windows环境搭建

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 为什么会要用到pthread库&#xff1f;一、pthread库下载二、使用步骤1.创建VS工程2.设置环境变量2.1动态载入2.2静态载入 三、结语 为什么会要用到pthread库&#x…

pthread_cond_timedwait函数使用

1 函数原型 #include <pthread.h>int pthread_cond_timedwait(pthread_cond_t *restrict cond,pthread_mutex_t *restrict mutex,const struct timespec *restrict abstime); int pthread_cond_wait(pthread_cond_t *restrict cond,pthread_mutex_t *restrict mutex); …