Coder Social home page Coder Social logo

jagged-teeth / 42-webserv Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ouafabulous/webserv_42

0.0 0.0 0.0 30.44 MB

A homemade HTTP webserv from scratch

Shell 0.01% JavaScript 8.43% C++ 4.78% Python 0.62% PHP 0.04% CSS 11.59% Makefile 0.05% HTML 74.49%

42-webserv's Introduction

Please find the project's documentation here.


Usage

./webserv [**_configuration_file_**](#configuration-files-format)

Configuration files format:

The format of our configuration files are directly inspired from NGINX.

There is two types of data:

  • directives
  • block

Directives

Directives are mades as follow:

keyword:	value;

Blocks

Blocks are used to provide contextual data within a scope. The scope is surrounded by curly brackets. There are two kinds of blocks:

  • Server block
  • Location block

Server block

Location blocks are used to differentiate the behavior of your server based on the address and port requested by the client.

server {
	listen			8080;				# listening port [REQUIRED]
	server_names	42.fr www.42.fr;	# Will match HTTP Header-field `Host`
	location / { ... }					# zero or more location blocks
}

Location block

Location blocks are used to differentiate the behavior of your server based on the path requested by the client (URI path in the HTTP start-line). They inherit the directives from the parent block (server or location). Each of these scopes defines a route.

List of available directives

specific server block directive

  • listen: unsigned int - represents the port on which the virtual server is listening
  • server_names: one or more URI separated by space(s) - matches with the HTTP Header-field Host

one definition directive

  • allowed_methods: zero or more flags (GET | POST | DELETE) separated by space(s) - HTTP request methods allowed for the route
  • client_max_body_size: unsigned int - maximum request body size (in bytes) allowed for the route
  • redirect: URI - request made on this route will be answered by a Moved Permanently (308) response pointing to this URI
  • root: path - path which the server will use to serve files requested by the client
  • index: filename - filename used to resolve a request pointing to a directory path
  • autoindex: (on | off) - if on, a request pointing to a directory path will be answered by an HTML representation of the files contained in the directory

multiple definition directive

  • cgi_setupt: file-extention and path-to-the-binary, separated by a space - if a request is pointing to a file that ends with the file-extention, it will be answerd by the STDOUT of this file given as an argument to the path-to-the-binary executable
  • error_file: status-code and path-to-error-file, separated by a space - if an error occured with the same statuts-code as the one set, the server will respond by sending the file at path-to-error-file

Examples

Example 1: Simple server configuration

This configuration sets up a server that listens on port 8080 and responds to requests on the / route.

server {
	listen 8080;
	server_names 42.fr www.42.fr;
	root /var/www/html;
	index index.html;
	autoindex on;
	location / {
		allowed_methods GET POST;
		client_max_body_size 1024;
	}
}

Example 2: Redirect configuration

This configuration redirects requests to the root route to a new URL.

server {
	listen 8080;
	server_names 42.fr
	location / {
		redirect /new-location;
	}
	location /new-location {
		root /var/www/new-location;
		index index.html;
	}
}

Example 3: CGI configuration

This configuration sets up a CGI script to handle requests for .py files.

server {
	listen 8080;
	server_names 42.fr;
	location / {
		root /var/www/html;
		index index.html;
		cgi_setup .py /usr/bin/python3;
	}
}

Note that these are just examples, and you will need to adjust them to match the specific needs of your application.

42-webserv's People

Contributors

ouafabulous avatar misteriaud avatar jagged-teeth 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.