WEB?
HTTPHTTP
ApacheApache
NginxNginx
HTTP
● Text based protocl defined in 1991
● V0.9 defined default port 80
● uses TCP/IP connection but should be able to run
on any connection oriented protocol
● RFCs 2616, 5785, 6266, 6585, 3986, 6874
HTTP vs. Gopher
● HTTP defines HTML as formatting for documents
● Gopher defines menu style format
● HTTP does not define any easy for searching and
indexing pages
● Trough its simple structure, gopher allows easy
search and indexing
● HTTP 80rfc2616 Gopher 70rfc1436
● Gopher defined the URI standard
HTTP
– Methods
– Requests
– Responses
– Headers
– URI/URL
– CGI
HTTP Methods
Method URI Proto
GET /lib/ana/sex.txt HTTP/1.0
● GET
● HEAD
● POST
● OPTIONS
● TRACE
● PUT
● DELETE
HTTP Requests
Method URI Proto + CRLF
HEADER + CRLF
HEADER + CRLF
CRLF
GET /pics/ana/naked.jpg HTTP/1.0 + CRLF
Range: 2400-2600,2900-3200 + CRLF
CRLF
HTTP Responses
GET /pics/ana/naked.jpg HTTP/1.0 + CRLF
Range: 2400-2600,2900-3200 + CRLF
CRLF
Proto Status Reason
HTTP/1.0 200 OK + CRLF
Response headers + CRLF
CRLF
.... binary data here .....
HTTP proto differences
● HTTP/1.0
– close connection after each request
● HTTP/1.1
– Host header
– Connection: keep-alive
– CONNECT method
Uniform Resource Identifier
(URI)
● UR Locator - URL
● Protocols: file, http, https, ftp, ftps, mailto, telnet,
ssh, smb, irc
proto :// user:pass @ host : port / path ? params
params:
param=value & param=value
Common Gateway Interface
(CGI)
● CGI is not Computer Generated Imagery :)
Web Server
Dynamic Content Generator
(CGI script)
SERVER_SOFTWARE
SERVER_NAME
GATEWAY_INTERFACESERVER_PROTOCOL
SERVER_PORT
REQUEST_METHOD
PATH_INFO - request path
PATH_TRANSLATED - full fs path
SCRIPT_NAME - request path
QUERY_STRING
REMOTE_HOST
REMOTE_ADDR
AUTH_TYPE
REMOTE_USER
REMOTE_IDENT
CONTENT_TYPE
CONTENT_LENGTH
Common Gateway Interface
(CGI)
● CGI is not Computer Generated Imagery :)
Web Server
Dynamic Content Generator
(CGI script)
/bin/sh + special
environment variables
1. Create a new environment
2. Create a new shell process
3. Execute the script
Note: the script must be executable and must
be able to produce the required output.
Responses must start with:
Content-type: some-type + CRLF
Responses may include Status codes:
200 OK + CRLF
Apache
● Documentation
● Module architecture
● Multi-processing Modules (MPMs)
● Additional Modules
MPMs - Prefork
● mpm_common
● Prefork
● Worker
● Event
Child
Child
Child
Memory
Memory
Memory
Memory
Main
Process
MPMs - Worker
● mpm_common
● Prefork
● Worker
● Event
Child
Child
Child
Main Process
Memory
MPMs - event
● mpm_common
● Prefork
● Worker
● Event
desc_ready = select(1, &rfds, NULL, NULL, &tv);
for (i=0; i <= max_fd && desc_ready > 0; ++i) {
VS.
for (;;) {
nfds = epoll_wait(epollfd, events, MAX_EVENTS, -1);
Module structure - Startup
● Pre-Config
● Test Configuration
● Post Configuration
● Open Logs
● Child Init
– Note that all of these are performed at least two times!
Module structure - Request
● Pre-Connection
● Create Connection
● Process Connection
● Create Request
● Post-Read Request
● Header Parse
● HTTP Scheme
● Default Port
● Quick Handler
● Translate Name
● Map to Storage
● Check Access
● Verify User ID
● Verify User Access
● Check Type
● Fixups
● Insert Filters
● Content Handlers
● Logging
● Insert Errors
Apache - Content handlers
module_name module_file mime_type priority
cgi_module mod_cgi.c .cgi .pl .sh 10
php_module mod_php.c .php .php5 10
perl_module mod_perl.c .pl .pm 10
Apache - CGI execution
Apache
Child mod_php
Child mod_cgi
root
nobody
nobody
Child mod_cgi
Child mod_suphp
index.php
index.php
suexec
index.php
/bin/sh
/bin/sh
suphp
index.php/bin/sh
user
user
Apache - CGI execution
Apache
Child mod_fcgid
Child mod_fcgid
root
nobody
user
index.php
FastCGI
daemon
child
child
child
index.php
index.php
suexec
Apache structure
● bin/
– httpd - the server
– ab - Apache Bench
– apxs - externel module builder
– htpasswd
– suexec
● conf/
– httpd.conf
– mime.typs + magic
● modules/ (libexec on 1.3)
● logs/

LSA2 - 03 Http apache nginx

  • 1.
  • 2.
    HTTP ● Text basedprotocl defined in 1991 ● V0.9 defined default port 80 ● uses TCP/IP connection but should be able to run on any connection oriented protocol ● RFCs 2616, 5785, 6266, 6585, 3986, 6874
  • 3.
    HTTP vs. Gopher ●HTTP defines HTML as formatting for documents ● Gopher defines menu style format ● HTTP does not define any easy for searching and indexing pages ● Trough its simple structure, gopher allows easy search and indexing ● HTTP 80rfc2616 Gopher 70rfc1436 ● Gopher defined the URI standard
  • 4.
    HTTP – Methods – Requests –Responses – Headers – URI/URL – CGI
  • 5.
    HTTP Methods Method URIProto GET /lib/ana/sex.txt HTTP/1.0 ● GET ● HEAD ● POST ● OPTIONS ● TRACE ● PUT ● DELETE
  • 6.
    HTTP Requests Method URIProto + CRLF HEADER + CRLF HEADER + CRLF CRLF GET /pics/ana/naked.jpg HTTP/1.0 + CRLF Range: 2400-2600,2900-3200 + CRLF CRLF
  • 7.
    HTTP Responses GET /pics/ana/naked.jpgHTTP/1.0 + CRLF Range: 2400-2600,2900-3200 + CRLF CRLF Proto Status Reason HTTP/1.0 200 OK + CRLF Response headers + CRLF CRLF .... binary data here .....
  • 8.
    HTTP proto differences ●HTTP/1.0 – close connection after each request ● HTTP/1.1 – Host header – Connection: keep-alive – CONNECT method
  • 9.
    Uniform Resource Identifier (URI) ●UR Locator - URL ● Protocols: file, http, https, ftp, ftps, mailto, telnet, ssh, smb, irc proto :// user:pass @ host : port / path ? params params: param=value & param=value
  • 10.
    Common Gateway Interface (CGI) ●CGI is not Computer Generated Imagery :) Web Server Dynamic Content Generator (CGI script) SERVER_SOFTWARE SERVER_NAME GATEWAY_INTERFACESERVER_PROTOCOL SERVER_PORT REQUEST_METHOD PATH_INFO - request path PATH_TRANSLATED - full fs path SCRIPT_NAME - request path QUERY_STRING REMOTE_HOST REMOTE_ADDR AUTH_TYPE REMOTE_USER REMOTE_IDENT CONTENT_TYPE CONTENT_LENGTH
  • 11.
    Common Gateway Interface (CGI) ●CGI is not Computer Generated Imagery :) Web Server Dynamic Content Generator (CGI script) /bin/sh + special environment variables 1. Create a new environment 2. Create a new shell process 3. Execute the script Note: the script must be executable and must be able to produce the required output. Responses must start with: Content-type: some-type + CRLF Responses may include Status codes: 200 OK + CRLF
  • 12.
    Apache ● Documentation ● Modulearchitecture ● Multi-processing Modules (MPMs) ● Additional Modules
  • 13.
    MPMs - Prefork ●mpm_common ● Prefork ● Worker ● Event Child Child Child Memory Memory Memory Memory Main Process
  • 14.
    MPMs - Worker ●mpm_common ● Prefork ● Worker ● Event Child Child Child Main Process Memory
  • 15.
    MPMs - event ●mpm_common ● Prefork ● Worker ● Event desc_ready = select(1, &rfds, NULL, NULL, &tv); for (i=0; i <= max_fd && desc_ready > 0; ++i) { VS. for (;;) { nfds = epoll_wait(epollfd, events, MAX_EVENTS, -1);
  • 16.
    Module structure -Startup ● Pre-Config ● Test Configuration ● Post Configuration ● Open Logs ● Child Init – Note that all of these are performed at least two times!
  • 17.
    Module structure -Request ● Pre-Connection ● Create Connection ● Process Connection ● Create Request ● Post-Read Request ● Header Parse ● HTTP Scheme ● Default Port ● Quick Handler ● Translate Name ● Map to Storage ● Check Access ● Verify User ID ● Verify User Access ● Check Type ● Fixups ● Insert Filters ● Content Handlers ● Logging ● Insert Errors
  • 18.
    Apache - Contenthandlers module_name module_file mime_type priority cgi_module mod_cgi.c .cgi .pl .sh 10 php_module mod_php.c .php .php5 10 perl_module mod_perl.c .pl .pm 10
  • 19.
    Apache - CGIexecution Apache Child mod_php Child mod_cgi root nobody nobody Child mod_cgi Child mod_suphp index.php index.php suexec index.php /bin/sh /bin/sh suphp index.php/bin/sh user user
  • 20.
    Apache - CGIexecution Apache Child mod_fcgid Child mod_fcgid root nobody user index.php FastCGI daemon child child child index.php index.php suexec
  • 21.
    Apache structure ● bin/ –httpd - the server – ab - Apache Bench – apxs - externel module builder – htpasswd – suexec ● conf/ – httpd.conf – mime.typs + magic ● modules/ (libexec on 1.3) ● logs/