Giter Club home page Giter Club logo

w3bs3rv's Introduction

C++ macOS

Webserv

This project presents a web server that has been developed from scratch in C++, utilizing a configuration file similar to that of the widely-used nginx. The web server incorporates a parser and lexer for interpreting the configuration file, allowing for a high degree of customization to suit the specific needs of the user.

The key features of this web server include:

  • The use of I/O multiplexing to handle multiple clients concurrently, ensuring efficient and speedy handling of incoming requests.
  • Support for Common Gateway Interface (CGI) on custom paths, enabling the execution of scripts and dynamic content.
  • Compliance with industry standards by adhering to the relevant RFCs.
  • The ability to handle cookies and sessions.
  • Can handle request time-out.

Building

To build this project you need autoconf installed on your computer.

# Clone this repository
$ git clone https://github.com/ahkecha/w3bs3rv

# Go into the repository
$ cd w3bs3rv

# Run configure script
$ ./configure

# build the executable
$ make -C build/

โš™๏ธ Configuration

Webserv uses a custom configuration syntax, similar to nginx config files

Example

server {
	listen 8685; # ip:port
	server_name webserv.42
	root www/root;
	index internet.html;
	autoindex on;
	upload www/root/uploads; #file upload directory
	error_page 404 www/root/custom_404.html; #custom error pages
	allowed_methods GET,POST;
	client_max_body_size 6000000;

	location /favicon.ico {
		deny all;
	}

	location /intra {
		redirect http://profile.intra.42.fr;
	}

	location /python {
		root www/root/python;
		autoindex off;
		index index.py;
		allowed_methods GET,POST;
		cgiExt py;
		cgiPath /usr/local/bin/python3.9;
	}

	location /perl {
		root www/root/perl;
		allowed_methods GET,POST;
		cgiExt pl;
		cgiPath cgi-bin/perl;
	}

	location /php {
		allowed_methods GET,POST;
		cgiPath cgi-bin/php-cgi;
		cgiExt php;
	}
 }

The configuration file above serves as an example of the various directives that can be utilized to tailor the web server to the specific needs of the user:

  • listen: used to specify the IP address and port on which the server will listen for incoming requests.
  • root : sets the default root directory for the server(can be overriden in specific locations).
  • index : specifies the default file to be served when no specific file is requested.
  • autoindex : (self explanatory) when set to "on" will automatically generate a directory listing when a directory is requested.
  • upload: specify a directory for handling file uploads.
  • error_page: allows for custom error pages to be served for specific error codes.
  • allowed_methods: specifies which HTTP methods are allowed for a given location.
  • location which is used to specify specific parameters for a specific route, such as a separate root directory or allowed methods as well as CGI path and Extension.

In the example configuration file, specific locations have been defined for handling different types of content, such as "static" and "video" locations, as well as locations for executing scripts written in Python, Perl, and PHP using the "cgiExt" and "cgiPath" directives. Additionally, a location for handling login requests and file uploads has been defined, with the appropriate allowed methods specified.

Usage

If no config file is supplied, webserv will use the default config file located in config/default.conf

$ ./webserv PATH_TO_CONFIG_FILE

Overall, this web server provides a high degree of flexibility and configurability, allowing for easy customization to suit the specific needs of the user. With its efficient handling of multiple clients and support for CGI, this web server is a robust and reliable solution for serving web content.

Authors

avatar
ahkecha

avatar
oabdelha

w3bs3rv's People

Contributors

ahkecha avatar c0m-m4nd0 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.