Ubuntu16下HTTP服务器配置.docx
计算机网络实验报告实验名称:http服务器的安装和配置学号、姓名:张焓实验 日期:2016-10-14 实验报告日期:2016-10-14实验地点:小组成员分工:一实验目的1、基础配置观察实验:用wireshark抓包分析2、Linux下完成HTTP服务器的安装和配置3、HTTP服务器测试二.实验环境1. 实验设备:软件:linux ubuntu, Windos, Wireshark;硬件:PC 1台2. 网络拓扑结构图如下:三 实验内容及步骤、实验的详细记录、实验结果分析(写出每个命令执行时,所显示的内容,实验中遇到的问题和思考。)1. 安装 apache2米用命令:sudo apt-get install apache2:Ubuntu 副本(备份 1)正在运行-Oracle VM VirtualBox管理控制视图热键设备帮助I* 食邕处 IS3 V) 10:46 4X' 一匚1终端文件(F)编辑(E)查看(V)搜索(S)终端(T)帮助(H)hanQhan-VirtualBoxsudo apt-get install apache2 正在读取软件包列表.完成 正在分析软件包的依赖关系树 正在读取状态信息.完成将会同时安装下列软件:apache2-bin apache2-data apache2-utils libaprl libaprutilllibaprutill-dbd-sqlite3 libaprutill-Idap libluaS.1-0建议安装:apache2-doc apache2-suexec-pristine I apacheZ-suexec-custom下狗【新】软件包将被安装:apache2 apacheZ-btn apache2-data apache2-uttls libaprl libaprutilllibaprutill-dbd-sqlite3 libaprutill-Idap ItbluaS.l-O升级了 0个软件包,券安装了 9个软件包,囊卸载0个软件包,有392个软件包未被升 级。需要下载"537 kB的归档。解压缩后会掐耗6,350 kB的额外空间。您希望继续执行吗? Y/n y获取:1 http:/cn. archive, ubuntu .con/ubuntu -3 86.0 kB获耳又:2 http:/cn.archive.ubuntu.con/ubuntu.5.4-lbuildl 77.1 kB获取:3 http:/ /cn.archive.ubuntu.con/ubuntuite3 and64 1.5.4-lbuildl 10.6 kB获取:4 http:/cn.archive.ubuntu.con/ubuntuxenial/matnxenial/mainxenial/matnxenial/matnamd64amd64amd64libaprl amd64 1.5.2amd64Ubuntu Kylinlibaprutill amd64 1libaprutiH-dbd-sqllibaprutill-Idap am在浏览器输入localhost查看是否成功安装Ubuntu 副本(备份 1)正在运行-Oracle VM VirtualBoxUbuntu systems. It is based on the equivalent page on Debian, from which the Ubuntu Apache packaging is derived. If you can read this page, it means that the Apache HTTP server installed at this site is working properly. You should replace this file (located at /va r/www/html/index. html) before continuing to operate your HTTP server.管理控制视图热键设备帮助J Apache2 | 127.0.0.1If you are a normal user of this web site and don't know what this page is about, this probably means that the site/etc/apache2/- apache2.confI '.- ports.conf/- mods-enabledIQi Ql (g).园©蓟部云三酱(3彩Right Ctrl2. 配置 apache2编辑 apache2.conf:sudo vi /etc/apache2/apache2.confUbuntu 副本(备份 1)正在运行-Oracle VM VirtualBox管理控制视图热键设备帮助I* 宜蜃画 V) 13:27 4X _ B 文件编辑查看历史书签工具帮助X _ I终端文件(F)编辑(E)查看(V)搜索(S)终端(I)帮助(H)your system is serving content from a sub-directory in /srv you must allow access here, or in any related virtual host.irectory />Options FollowSymLinksAllowOverride NoneRequire all deniediry /usr/share> AllowOverride None Require all grantediry /var/www/> tOptions Indexes FbllowSynLtnksAllowOverride NoneRequire all granted:ory /srv/>Options Indexes FollowSymLinks AllowOverride None151,175%删除原有的index.html,并创建一个新的index.htmlPS:这里可能需要重启一下 apache2 服务:sudo /etc/init.d/apache2 restartRequire all granted期 Ubuntu 副本(备份 1)正在运行-Oracle VM VirtualBox 管理控制视图热健设备帮助|X 一 口终端文件(F)编辑(E)查看(V)搜索(S)终端(T)帮助(H)hanQhan-VirtualBoxvt /etc/apache2/apache2.confhanghan-VirtualBoxsudo rm /var/www/html/tndex.htnlsudo han 的密码:hanghan-VirtualBoxsu密码:rootghan-VirtualBox:/home/han# cd /var/www/htmlrootghan-VirtualBox:/var/www/html# echo "this is a test web for zh"»index.html rootghan-VirtualBox:/var/www/html# |Ubuntu Kylin1。匚浏览器打开localhost变为:密 Ubuntu 副本(备份 1)正在运行-Oracle VM VirtualBox 管理控制视图热键设备帮助X _ 文件编辑查看历史书签工具帮助» 邕 函!») 13:20 O4 localhostI C I 叵搜索旧 D 命this is a test web for zh 彳 ° fli IB Qi eRight Ctrl3. 由客户端虚拟机访问服务端虚拟机:重新打开一个能与当前作为服务器的虚拟机互相ping通的虚拟机作为客户端,在浏 览器输入服务器IP: 192.168.137.2(上为服务器虚拟机,下为客户端虚拟机,可能需要在 服务器中重启一下dhcp服务)羽 Ubuntu 副本(备份 1)正在运行-OracleVMVirtualBox X管理控制视图热键设备帮助X _ 文件编辑查看历史书签工具帮助通邕 由») 13:21 OJhttp:/localhost/定 | localhost| |Q 搜索旧 D 命t转到二页 lZh右击或下拉显示历史景 Ubuntu 正在运行-Oracle VM Virtual Box 管理控制视图热键设备帮助X _ 文件编辑查看历史书签工具帮助http:/192.168.137.2/X6 © 192.168.137. h ttp:/192.168.137.2/ this is a test web for zh4.nginx安装与配置安装:xenial-updates/matnxenial-updates/mainamd64 nginx-corexenial-updates/matnamd64 nginx all 1xenial-updates/matnUbuntu Kylin1386 nginx-common1386 nginx-common管理控制视图热键设备帮助配置文件,将端口号由80改为88:X: _ 终端文件(F)编辑(E)查看(V)搜索(S)终端(T)帮助(H)hanQhan-VirtualBox:$ sudo apt-get install nginx sudo han 的密码:隹在强取软件包列表.完成 正在分析软件包的依赖关系树 正在读取状态信息.完成|将会同时安装下列软件:nginx-common nginx-core建设安装:fcgiwrap nginx-doc下列【新】软奔包将被安装:nginx nginx-common ngtnx-core升缓了 0个软件包,新安装了 3个软件包,要卸载0个软件包,有392个软件包未被升 |虱需要下载457 kB的归档。解压缩后会消耗1,48。kB的额外空间。您希望继续执行吗? Y/n V忽略:1 http:/cn all 1.10.0-OubuntuO.16.04.2获取 amd64 1.10.0-Oubuntu0.16.04.2 428 kB 获取:3 http:/cn.archive.ubuntu.con/ubuntu .10.0-Oubuntu0.16.O4.2 3,498 B获取:1 http: /cn .archive. ubuntu. com/ubuntuall 1.10.O-OubuntuO.16.04.2 25.6 kBlisten 88 listen :Default serverI defaultSSL configurationconfigurationdefault_server;:88 default_server;Generally, you will want to move this file somewhere, and start with a clean file but keep this around for reference. Or just disable in sttes-enabled.Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.X _ 口终端文件(F)编辑(E)查看(V)搜索(S)终端(!)帮助(H)# # # #期 Ubuntu 副本(备份 1)正在运行-Oracle VM Virtual Box 管理控制视图热键设备帮助You should look at the following URL's in order to grasp a solid understanding of Nginx configuration files in order to fully unleash the power of Nginx.http:/wiki.nginx.org/Pitfallshttp:/wiki.nginx.org/QuickStarthttp:/wiki.nginx.org/Configurationlisten 443 ssl default_server;listen :443 ssl default_server;86L, 2074C"4,1顶端关闭apache2服务,重启nginx服务,并测试:管理控制视图热键设备帮助X _ 终端文件(F)编辑(E)查看(V)搜索(S)终端(T)帮助(H)nstatzipsplitnsupdatezjsdecodentfsdecryptzlib-flatevi defaultvi defaultsudo /etc/init.d/nglnx restarthanhan-VirtualBox:/usr/bin$ cd /etc hanhan-VirtualBox:/etc$ cd nginx hanhan-VirtualBox:/etc/ngtnx$ cd sites-avatlable hanhan-VirtualBox:/etc/ngtnx/sttes-available$ default hanhan-VirtualBox:/etc/nginx/sites-avatlable$ hanQhan-VirtualBox:/etc/nginx/sites-available$ hanhan-VirtualBox:/etc/ngtnx/sttes-available$vi defaultsudo vt defaultsudo /etc/init.d/nginx restart. Restarting nginx (via systemctl): ngtnx.serviceJob for ngtnx.service fail ed because the control process exited with error code. See "systemctl status ngi nx.service" and Mjournalctl -xeM for details.hanhan-VirtualBox:/etc/ngtnx/sttes-available$ hanhan-VirtualBox:/etc/ngtnx/sttes-available$ hanQhan-VirtualBox:/etc/nginx/sites-available$ ok Restarting nginx (via systemctl): nginx.service. hanQhan-VirtualBox:/etc/nginx/sites-available$ sudo /etc/init,d/apache2 stop ok Stopping apache2 (via systemctl): apache2sevtce. hanhan-VirtualBox:/etc/ngtnx/sttes-available$ sudo /etc/init>d/ngtnx restart ok Restarting nginx (via systemctl): nginx.service.hanhan-VirtualBox:/etc/ngtnx/sttesavatlable$ 口X _ 文件编辑查看历史书签工具帮助,http:/localhost:88/。i | localhost:88this is a test web for zhEr r MBEIu1 fllL客户端测试:Ubuntu 副本(备份 1)正在运行-Oracle VM VirtualBox管理控制视图热键设备帮助X _ D 文件编辑查看历史书签工具帮助http:/localhost:88/xej |Q搜索产-、I © localhost:88this is a test web for zhUbuntu 正在运行-Oracle VM VirtualBox管理控制视图热键设备帮助X _ D 文件编辑查看历史书签工具帮助+http:/192.168.137.2/ Xc | |q搜索« © | 192.168.137.2转到上一页右击或下拉显示历史,rzh5.HTTP协议在客户端打开wireshark,进行抓包分析;在此期间,在浏览器输入192.168.137.2 (服 务器IP地址),在wireshark中有如下结果: Hypertext Transfer Protocol HTTP/1.1 304 Not ModifiedrnF http:/192.168.137.2/No. TimeSourceDestinationProtoc Length Info472 GET / HTTP/1.1246 HTTP/1.1 304 Not Modifie.472 GET / HTTP/1.1246 HTTP/1.1 304 Not Modifie.http表达式.+23 6.138872310192.168.137.10125 6139725364192.168.137.2131 82.598754807 192.168.137.101133 82.599286821 192.168.137.2192.168.137.2192.168.137.101192.168.137.2192.168.137.101HTTPHTTPHTTPHTTPDate: Fri, 14 Oct 2016 05:52:02 GMTrn"Ia-53ecccbc79b20"rnresponse 1/1since request: 0.000853054 secondsConnection: Keep-AlivernKeep-Alive: timeout=5, max=100rnETag :rnHTTPTimeRequest in frame: 23Ubuntu 正奁行-Oracle VM VirtualBox管理控制视图热键设备帮助。© | 192.168.137.2this is a test web for zh园®包淳 旦酱晦笏±j Right CtrlX 一口 文件(F)编辑(E)视图(V)跳转(G)捕获(C)分析(A)统计(S)电话(Y)无线(W)工具(T)帮助(H)Server: Apache/2.4.18 (Ubuntu)rn念 18°C 画奥 t. S) <) 13:55X _ 文件编辑查看历史书签工具帮助分析报文23,可以发现这是一条由客户端192.168.137.101发送至服务器192.168.137.2的请求报文,采用HTTP/1.1协议,发送时间是2016年十月十四日,05:49:56:朗 Ubuntu 正在运行-Oracle VM VirtualBox管理控制视图热键设备帮助念 18°C 宜国,,巨)V) 13:56X _ B 文件编辑查看历史书签工具帮助http:/192.168.137.2/X Expert Info (Chat/Sequence): GET / HTTP/1.lrn ® 192.168.137.2|X| 口 wireshark 分组 23 wireshark_pcapng_enp0s8_20161014135158.E57VXNFrame 23: 472 bytes on wire (3776 bits), 472 bytes captured (3776 bits) on int Ethernet II, Src: CadmusCo_ee:47:b5 (08:00:27:ee:47:b5), Dst: CadmusCo_ee:47:b Internet Protocol Version 4, Src: 192.168.137.101, Dst: 192.168.137.2 Transmission Control Protocol, Src Port: 37142 (37142), Dst Port: 80 (80), SeqHypertext Transfer Protocol v GET / HTTP/1.lrnHost: 192.168.User-Agent: MoAccept: text/hAccept-Languagi08 00 27 ee 47 b5 08 00 27 ee 47 b5 08 00 4500 be 51 c0 a8 89 65 c0 a825 6.1397253C131 82.5987541133 82.599286E= this is a test web for z23 6.13887231Frame 23: 472 by Ethernet II, Src Internet Protoco Transmission Con Hypertext Transfi GET / HTTP/1.1Request Method: GETRequest URI: / Request Version: HTTP/1.1 Host: 192.168.137.2rn User-Agent: Mozilla/5.0 (Xll; Ubuntu; Linux x86_64; rv:48.0) Gecko/20100101 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q二。.8rn Accept-Language: en-US,en;q=0.5rn Accept-Encoding: gzip, deflatern Connection: keep-alivern Upgrade-Insecure-Requests: If-Modified-Since: Fri, 14 If-None-Match: Hla-53ecccbc79b20"rn rn Full request URI: http:/192.168.137.2/1Accept-Encoding: gzip, deflatern分析相应的请求返回包报文25,可以发现这是一条由客户端192.168.137.2发送至服务器192.168.137.101的请求报文,采用HTTP/1.1协议,时间是2016年十月十四日,05:52:02,还可以看到 HTTP 服务器版本是 APACHE/2.4.18(Ubuntu)this is a test web for zlI I http"Ia-53ecccbc79b20"rnNo.: 2S Time: 6.139725364 . Source: 192.168.137.2 - Destination:. Protocol: HTTP Length: 246 . Info: HTTP/1.1304 Not Modified园©棘臣 w皆辑笏u Right Ctrlresponse 1/1 since request: 0.000853054 secondsKeep-Alive: timeout二5, max=100rn ETag: rn HTTP Time Request in frame: 2308 007 ee 47 b5 08 00 27 ee 47 b5 08 00 45 00. . r .G. . . ' .G. . .E.00 e8 3c 3e 40 00 40 06 6a 19 c0 a8 89 02 c0 a8.j二防65醐I No.TimeI23*6.1388723:25 6.1397253C131 82.598754133 82.599286E Frame 25: 246 回 Ethernet II, Src Internet Protoco Transmission Con hypertext TransfiV HTTP/1.1 364 N Expert InfcRequest Vers Status Code: Response PhraDate: Fri, 14 Oct 2016 05:52:02 GMTrnFrame 25: 246 bytes on wire (1968 bits), 246 bytes captured (1968 bits) on int. Ethernet II, Src: CadmusCo_ee:47:b5 (08:00:27:ee:47:b5), Dst: CadmusCo_ee:47:b. Internet Protocol Version 4, Src: 192.168.137.2, Dst: 192.168.137.101 Transmission Control Protocol, Src Port: 80 (80), Dst Port: 37142 (37142), Seq. Hypertext Transfer Protocol HTTP/1.1 304 Not Modifiedrn Expert Info (Chat/Sequence): HTTP/1.1 304 Not ModifiedrnRequest Version: HTTP/1.1 Status Code: 304 Response Phrase: Not ModifiedDate: Fri, 14 Oct 2016 05:52:02 GMTrnServer: Apache/2.4.18 (Ubuntu)rnF http:/192.168.137.2/Ubuntu 正在运行-Oracle VM VirtualBox管理控制视图热键设备帮助 © | 192.168.137.2X 口 Wireshark > 分蛆 25 - wireshark_pcapng_enp0s8_20161014135158_E57VXNX _ 文件(F)Connection: Keep-Alivern绘 18°C 宜奥画 V) 14:00X _ 文件编辑查看历史书签工具帮助四. 思考题回答五. 实验总结在这次实验中,我了解了 HTTP的相关概念、工作原理及其作用。掌握了如何在Linux 下安装HTTP服务器软件,并在实验中成功地设置了 HTTP服务器,并在客户端成功地访问 了该服务器,并且知道了如何正确配置HTTP服务器,并学会了如何借此搭建一个HTTP服 务器。