Skip to main content

HTTP request methods; web server and virtual hosting

Short answer

Key HTTP methods: GET (retrieve), POST (submit), HEAD (headers). Web server config: set IP, install, define ServerName/DocumentRoot, open port, restart. Virtual hosting: IP-based, port-based, name-based (uses Host header).

Explain the request methods of HTTP? Write the major steps while configuring web server and the types of web hosting (Virtual Hosting) from your web server.

HTTP request methods

The first line of an HTTP request is: METHOD URL VERSION. The main methods:

MethodPurpose
GETRetrieve the resource named by the URL. Data in the query string; no body. Safe and idempotent.
POSTSend data (form input, file upload) in the body for the server to process.
HEADLike GET but the server returns only headers, not the object. Used to check size/modification time.
PUTUpload/replace the resource at the URL.
DELETERemove the resource at the URL.
OPTIONSAsk which methods the server supports.
TRACEEcho the request back, for diagnostics.
CONNECTMake a tunnel through a proxy (used for HTTPS).

Example: GET /index.html HTTP/1.1 with header Host: www.example.com.

Major steps to configure a web server (Apache on Linux)

  1. Assign a static IP address and set a host name; set up DNS (A record) for the site.
  2. Install the software: yum install httpd or apt install apache2.
  3. Edit the main configuration (httpd.conf / apache2.conf): Listen 80, ServerName, DocumentRoot /var/www/html, DirectoryIndex index.html, access rules in <Directory>.
  4. Put the web pages in the document root and set file permissions.
  5. Open port 80 (443 for HTTPS) in the firewall.
  6. Test syntax (apachectl configtest), start and enable the service (systemctl enable --now httpd).
  7. Browse to http://server-ip/ and check the logs in /var/log/httpd/.

Types of virtual hosting

Virtual hosting lets one server host several sites.

  • IP-based: each site has its own IP address; <VirtualHost 192.168.1.10:80>.
  • Port-based: same IP, different ports; <VirtualHost *:8080>.
  • Name-based: same IP and port, selected by the HTTP Host: header.
<VirtualHost *:80>
    ServerName www.a.com
    DocumentRoot /var/www/a
</VirtualHost>
<VirtualHost *:80>
    ServerName www.b.com
    DocumentRoot /var/www/b
</VirtualHost>

Name-based hosting is the most economical because only one IP address is needed. IP-based hosting is required when each site needs its own SSL certificate on old clients.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Internet and Intranet chapter 4 questions →