/webserv

This project is about writing your own HTTP server. You will be able to test it with an actual browser

Primary LanguageC++

42 result

WebServer

42 project, recoding our own web server in c++ 98. webserv is a HTTP/1.1 server conditionnal compliant with RFC 7230 to 7235. HTTP is one of the most used protocols on the internet. Knowing its arcane will be useful, even if you won’t be working on a website. read the subject for more infrmetion.

Environment

  • MacOS 11.4(Big Sur, Intel)

Developed and tested in this environment.

Compile

To compile , run the lines below.

$ git clone https://github.com/moelazhari/inception.git
$ cd webserv
$ make

Execute

$ ./webserv [config_file] (config_file is set to ./www/html/configs/config if not specified)

type in the taype in your browser https://localhost:[port] to test

Configuration File

Configuration file is a text file that contains various settings and directives that dictate how the web server should operate. These settings are:
listen: listen 8001; set the port number to listen on. the port set to 80 if not specified.
host: host 127.0.0.1; set the ip address to listen on. the ip address set to 127.0.0.1 if not specified.
client_max_body_size: client_max_body_size 100; set the maximum size of the client request body, set to 10000 if not specified.
meme_types: mime_types types.conf; set the path to the mime.types file. the mime.types file set to ./www/html/configs/mime.types if not specified.
server_name: server_name localhost; set the virtual server name.
root: root ./www/html; set the root directory for the server. the root directory set to ./www/html if not specified.
index: index index.html index.htm; set the default file to serve when a directory is requested.
error_page: error_page 404 ./www/html/404.html; set the error page to serve when an error occurs.
location: location / { autoindex on; } set the location of the server.
autoindex: autoindex on; Turn on or off directory listing.
methods: methods GET POST; set the allowed methods. (supported methods: GET, POST, DELETE) set to all methods if not specified.
return: return 200 "Hello World"; set the return status code and the body of the response.
upload: upload on set on or off the upload feature. the upload feature is off by default.
cgi_path: cgi_path .php ./www/html/cgi-bin/php-cgi; set the cgi path to cgi executable that will handle the request with the specified extension.

example of configuration file

server {
	# default server;

	listen	8001;

	host 127.0.0.1;
	client_max_body_size 10000000;
	root ./www/html;
	error_page 404 www/html/error_pages/404.html;
	error_page 500 www/html/error_pages/500.html;
	allow_methods GET POST DELETE;
	autoindex on;
	index index.html index.php;
	meme_types ./configs/types.conf;


	location /favicon.ico {
		allow_methods GET POST DELETE;
		root ./www/html/favicon.ico;
	}

	location /upload{
		root ./www/html/upload;
		index upload.html;
		allow_methods POST GET;
		upload on;
	}

	location /cgi_bin {
		root ./www/html/cgi_bin;
		allow_methods GET POST;
		index hello.html;
		path_info .py /usr/bin/python3;
		path_info .php ./php-cgi;
	}

}

server {
	listen	8000;

	host 127.0.0.1;

	server_name moelazhari;
	client_max_body_size 26336;
	allow_methods GET POST DELETE;
	autoindex on;
	index server2.html;
	meme_types ./configs/types.conf;
}

server {
	listen	8003;

	host 10.11.6.13;
	client_max_body_size 26000;
	allow_methods GET POST DELETE;
	autoindex on;
	index server3.html;
	meme_types ./configs/types.conf;
}