Chapter 22 Web Hosting Computer Center CS NCTU
Chapter 22 Web Hosting
Computer Center, CS, NCTU Web Hosting – Basics (1) q Three major techniques in WWW (World Wide Web) System • HTML • HTTP • URL q HTML (1) – Hyper. Text Markup Language • Providing a means to describe the structure of text-based information in a document. • The original HTML is created by Tim Berners-Lee. • Published in 1993 by the IETF as a formal "application" of SGML (with an SGML Document Type Definition defining the grammar). • The HTML specifications have been maintained by the World Wide Web Consortium (W 3 C). Ø http: //www. w 3. org/ 2
Computer Center, CS, NCTU 3 Web Hosting – Basics (2) q HTML (2) • Mark-up the text and define presentation effect by HTML Tags. <html> <body>. . . Normal text <strong>Bold text</strong>. . . . </body> </html>
Computer Center, CS, NCTU Web Hosting – Basics (3) q HTTP – Hyper-Text Transfer Protocol • A TCP-based protocol • Communication method between client and server, both browsers and web servers have to follow this standard. • Originally designed to transmit HTML pages. • Now it is used to format, transmit, and link documents of variety media types Ø Text, picture, sound, animation, video, … • HTTPS – secured version. 4
Computer Center, CS, NCTU 5 Web Hosting – Basics (4) q URL – Uniform Resource Locator • Describe how to access an object shared on the Internet • Format Ø Protocol : // [ [ username [ : password ] @ ] hostname [ : port ] ] [ /directory ] [ /filename ] • ex: Ø http: //www. cs. nctu. edu. tw/ Ø ftp: //ftp. isu. edu. tw/ Ø telnet: //bs 2. to/
Computer Center, CS, NCTU 6 Web Hosting – Basics (5) q URL Protocols Proto What it does Example http Accesses a remote file via HTTP http: //www. csie. nctu. edu. tw https Accesses a remote file via HTTP/SSL https: //www. csie. nctu. edu. tw ftp Accesses a remote file via FTP ftp: //ftp. csie. nctu. edu. tw/ mailto Sends mailto: chwong@csie. nctu. edu. tw news Accesses Usenet newsgroups news: tw. bbs. comp. hardware telnet Logs in to a remote computer telnet: //bbs. csie. nctu. edu. tw file Access a local file: ///home/chwong/. tcshrc
Computer Center, CS, NCTU Web Hosting – Client-Server Architecture (1) q Client-server architecture • Web Server: Answer HTTP request • Web Client: Request certain page using URL 1. 以 URL 描述索取的資 源位置向 Server 發送要求 Client Browser 3. 從 URL 描述的位置將 HTML 文件取出並回覆給 Client 2. 以 HTTP 協定送出 Request Web Server 4. 以 HTTP 協定回覆 Response 5. 接收到 HTML 後由 Browser 解析後根據 HTML 描述定義將 資料呈現出來 7
Computer Center, CS, NCTU 8 Web Hosting – Client-Server Architecture (2) q Using “telnet” to web server chbsd [/home/chwong] -chwong- telnet www. cs. nctu. edu. tw 80 Trying 140. 113. 235. 111. . . Connected to www. cs. nctu. edu. tw. Escape character is '^]'. GET / HTTP/1. 0 200 OK Date: Wed, 27 Dec 2006 00: 46: 53 GMT Server: Apache Last-Modified: Wed, 25 Jan 2006 12: 31: 34 GMT ETag: "250404 -aa-b 5 eb 580" Accept-Ranges: bytes Content-Length: 170 Content-Type: text/html X-Cache: MISS from cswproxy. cs. nctu. edu. tw Via: 1. 0 cswproxy. cs. nctu. edu. tw: 80 (squid/2. 6. STABLE 3) Connection: close <html> <head> <title>NCTU -- CS</title> <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> <meta http-equiv="refresh" content="0; URL=chinese/doc/index. html"> </head> </html> Connection closed by foreign host.
Computer Center, CS, NCTU Web Hosting – The HTTP Protocol (1) q HTTP: Hypertext Transfer Protocol • RFCs: (HTTP 1. 1) http: //www. faqs. org/rfcs/rfc 2068. html http: //www. faqs. org/rfcs/rfc 2616. html (Updated Version) • Useful Reference: http: //jmarshall. com/easy/http/ • A network protocol used to deliver virtually all files and other data on the World Wide Web. Ø HTML files, image files, query results, or anything else. • Client-Server Architecture Ø A browser is an HTTP client because it sends requests to an HTTP server (Web server), which then sends responses back to the client. 9
Computer Center, CS, NCTU Web Hosting – The HTTP Protocol (2) • Clients: ※ Send Requests to Servers ※ Respond to the clinets Ø Action “path or URL” Protocal Ø Status: – Actions: GET, POST, HEAD – Ex. GET /index. php HTTP/1. 1 Ø Headers – Header_Name: value – Ex. From: someuser@jmarshall. com Ø (blank line) Ø Data … 10 • Servers: – – 200: OK 404: Not Found … Ex. HTTP/1. 1 200 OK Ø Headers – Same as clients – Ex. Content-Type: text/html Ø (blank line) Ø Data…
Computer Center, CS, NCTU Web Hosting – The HTTP Protocol (3) q Example: action Headers status Headers Data 11 sabsd [/home/chwong] -chwong- telnet sabsd. cs. nctu. edu. tw 80 Trying 140. 113. 17. 215. . . Connected to sabsd. cs. nctu. edu. tw. Escape character is '^]'. GET / HTTP/1. 0 Host: sabsd. cs. nctu. edu. tw HTTP/1. 0 200 OK Content-Type: text/html Accept-Ranges: bytes ETag: "1897433431" Last-Modified: Tue, 29 May 2007 06: 25: 04 GMT Content-Length: 94 Date: Tue, 29 May 2007 06: 25: 06 GMT Server: lighttpd/1. 4. 15 X-Cache: HIT from sabsd. cs. nctu. edu. tw Via: 1. 0 sabsd. cs. nctu. edu. tw: 80 (squid/2. 6. STABLE 13) Connection: close <html> <body> <a href="http: //sabsd. cs. nctu. edu. tw/~chwong/docs/"> haha </a> </body> </html> Connection closed by foreign host.
Computer Center, CS, NCTU Web Hosting – The HTTP Protocol (4) q Get vs. Post (client side) • Get: Ø Parameters in URL GET http: //sabsd. cs. nctu. edu. tw/get. php? a=1&b=3 HTTP/1. 1 Ø No data content Ø Corresponding in HTML files – Link URL: http: //sabsd. cs. nctu. edu. tw/get. php? a=1&b=3 – Using Form: <form method=“GET” action=“get. php”> … </form> • Post: Ø Parameters in Data Content POST http: //sabsd. cs. nctu. edu. tw/post. php HTTP/1. 1 Ø Corresponding in HTML files – Using Form: <form method=“POST” action=“post. php”> … </form> 12
Computer Center, CS, NCTU 13 Web Hosting – The HTTP Protocol (5) q HTTP Headers: • What HTTP Headers can do? [Ref] http: //www. cs. tut. fi/~jkorpela/http. html Ø Content information (type, date, size, encoding, …) Ø Cache control Ø Authentication Ø URL Redirection Ø Transmitting cookies Ø Knowing where client come from Ø Knowing what software client use Ø…
Computer Center, CS, NCTU Web Hosting – Static vs. Dynamic Pages (1) q Static vs. Dynamic Pages Static vs. Dynamic • Technologies of Dynamic Web Pages Ø Client Script Language – Java. Script, Jscript, VBScript Ø Client Interactive Technology – Java Applet, Flash, XMLHTTP, AJAX Ø Server Side – CGI – Languages: Perl, ASP, JSP, PHP, C/C++, …etc. 14
Computer Center, CS, NCTU 15 Web Hosting – Static vs. Dynamic Pages (2) q. Common Gateway Interface • A specification that allows an HTTP server to exchange information with other programs
Computer Center, CS, NCTU Web Hosting – Virtual Hosting (1) q Virtual Hosting • Providing services for more than one domain-name (or IP) in one web server. • IP-Based Virtual Hosting vs. Name-Based Virtual Hosting Ø IP-Base Ø Name-Base – Several IPs (or ports) – Singe IP, several hostnames • Example (Apache configuration) Name. Virtual. Host 140. 113. 17. 215 <Virtual. Host 140. 113. 17. 215> Server. Name nabsd. cs. nctu. edu. tw Document. Root "/www/na" </Virtual. Host> <Virtual. Host 140. 113. 17. 215> Server. Name sabsd. cs. nctu. edu. tw Document. Root "/www/sa" </Virtual. Host> 16 <Virtual. Host 140. 113. 17. 215: 80> Document. Root /www/sabsd Server. Name sabsd. cs. nctu. edu. tw </Virtual. Host> <Virtual. Host 140. 113. 17. 221: 80> Document. Root /www/tphp Server. Name tphp. cs. nctu. edu. tw </Virtual. Host>
Computer Center, CS, NCTU 17 Web Hosting – Virtual Hosting (2) Q: How Name-Based Virtual Hosting works? A: It takes use of HTTP Headers. % telnet cswproxy. cs. nctu. edu. tw 80 Trying 140. 113. 235. 111. . . Connected to cswproxy. cs. nctu. edu. tw. Escape character is '^]'. GET / HTTP/1. 0 Host: www. cs. nctu. edu. tw % telnet cswproxy. cs. nctu. edu. tw 80 Trying 140. 113. 235. 111. . . Connected to cswproxy. cs. nctu. edu. tw. Escape character is '^]'. GET / HTTP/1. 0 Host: www. csie. nctu. edu. tw HTTP/1. 0 200 OK Date: Tue, 05 Jun 2007 13: 50: 34 GMT HTTP/1. 0 200 OK Date: Tue, 05 Jun 2007 13: 51: 01 GMT ………… <html> <head> <title>NCTU -- CS</title> <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> <meta http-equiv="refresh" content="0; URL=chinese/doc/index. html"> </head> </html> Connection closed by foreign host. <html> <head> <title>NCTU -- CSIE</title> <meta http-equiv="refresh" content="0; URL=http: //www. cs. nctu. edu. tw/"> Connection closed by foreign host.
Apendix: Virtual Interface
Computer Center, CS, NCTU Virtual Interface q Idea • Let single machine responds to more IP addresses than it has physical network interfaces • Each of the virtual network interface can be associated with different domain name q Ex: • One NIC with two IP sabsd [/home/chwong] -chwong- ifconfig sk 0: flags=8843<UP, BROADCAST, RUNNING, SIMPLEX, MULTICAST> mtu 1500 options=b<RXCSUM, TXCSUM, VLAN_MTU> inet 140. 113. 17. 215 netmask 0 xffffff 00 broadcast 140. 113. 17. 255 inet 140. 113. 17. 221 netmask 0 xffff broadcast 140. 113. 17. 221 ether 00: 11: d 8: 06: 1 e: 81 media: Ethernet autoselect (100 base. TX <full-duplex, flag 0, flag 1>) status: active lo 0: flags=8049<UP, LOOPBACK, RUNNING, MULTICAST> mtu 16384 inet 127. 0. 0. 1 netmask 0 xff 000000 19
Computer Center, CS, NCTU 20 Virtual Interface Configuration – Free. BSD q Using “ifconfig” command “alias” option • % ifconfig sk 0 inet 140. 113. 17. 221 netmask 255 alias • % ifconfig sk 0 inet 140. 113. 17. 221 delete (when you want to delete it) q Specify in /etc/rc. conf ifconfig_sk 0="inet 140. 113. 17. 215/24" ifconfig_sk 0_alias 0="inet 140. 113. 17. 221/32" defaultrouter="140. 113. 17. 254" hostname=“sabsd" …
Computer Center, CS, NCTU Virtual Interface Configuration – Linux q Using ifconfig command • % ifconfig eth 0: 0 140. 113. 235. 6 netmask 255. 0 up q Add file under /etc/sysconfig/network-scripts/ • Original IP: /etc/sysconfig/network-scripts/ifcfg-eth 0 • Add /etc/sysconfig/network-scripts/ifcfg-eth 0: 0 DEVICE=eth 0: 0 BOOTPROTO=static BROADCAST=140. 113. 235. 255 IPADDR=140. 113. 235. 6 NETMASK=255. 0 NETWORK=140. 113. 235. 0 ONBOOT=yes 21
Computer Center, CS, NCTU 22 Virtual Interface Configuration – Solaris q Edit /etc/hostname. interface: 1 and /etc/inet/hosts q Ex: • /etc/hostname. hme 0 • Edit /etc/hostname. hme 0: 1 and /etc/inet/hosts ccsun 3 [/u/dcp/94/9455832] -chwong- cat /etc/hostname. hme 0: 1 ccsun 10 ccsun 3 [/u/dcp/94/9455832] -chwong- cat /etc/inet/hosts 127. 0. 0. 1 localhost 140. 113. 209. 103 ccsun 3 140. 113. 209. 110 ccsun 3 [/u/dcp/94/9455832] -chwong- ifconfig -a lo 0: flags=1000849<UP, LOOPBACK, RUNNING, MULTICAST, IPv 4> mtu 8232 index 1 inet 127. 0. 0. 1 netmask ff 000000 hme 0: flags=1000843<UP, BROADCAST, RUNNING, MULTICAST, IPv 4> mtu 1500 index 2 inet 140. 113. 209. 103 netmask ffffff 00 broadcast 140. 113. 209. 255 hme 0: 1: flags=1000843<UP, BROADCAST, RUNNING, MULTICAST, IPv 4> mtu 1500 index 2 inet 140. 113. 209. 110 netmask ffffff 00 broadcast 140. 113. 209. 255
- Slides: 22