Skip to content

Latest commit

 

History

History
155 lines (142 loc) · 4.59 KB

README.md

File metadata and controls

155 lines (142 loc) · 4.59 KB


Logo
Webserv Project for 42 Seoul

This repository is for the 42 seoul project Webserv.
The objective of this project is to implement own http server.

Note

This repository contains only a portion of the code related to parsing the configuration file.
Due to the fact that I am not the sole author of the project, I cannot share the full codebase.

Features

  • Support MacOS, Linux

Usage

  • You can execute file with one argument ConfigFile
  • If there is no argument, default config file will be created and excuted.
./webserv [config file]
  • Create your own config file in conf directory

Config

  • You can put multiple directives in proper context.
  • possible context: http, server, location, limit_except
  • directives can be nested from parent context.
  • If directive is not setted, default value can be inserted.

Http Context

Basic context. All configuration must be written in here.

possible directives
  • server
  • root
  • error_page
  • client_body_buffer_size
  • client_max_body_size
  • autoindex
  • index
  • deny

Server Context

Sets configuration for a virtual server. The first server in config file will be default server.

possible directives
  • location
  • listen
  • server_name
  • return
  • upload_store
  • root
  • error_page
  • client_body_buffer_size
  • client_max_body_size
  • autoindex
  • index
  • deny

Location Context

Sets configuration depending on a request URI.

possible directives
  • limit_except
  • cgi_script_pass
  • return
  • upload_store
  • root
  • error_page
  • client_body_buffer_size
  • client_max_body_size
  • autoindex
  • index
  • deny

Limit_Except Context

Sets possible http method.

possible directives
  • deny

If you want to know about syntax of each directives, see Nginx docs.
almost same.

Example

http {
        root "/tmp/html";
	# This will be default server. All unmatched request will be handled by this server.
        server {
                listen 80;
                listen [::]:80;
                server_name "localhost";
                index index.html;
                location /{
                        upload_store "/upload_from_client";
                        limit_except GET PUT {
                                deny all;
                        }
                        error_page 404                          404.html;
                        error_page 500 502 503 504      /50x.html;
                }
                location /upload_from_client {
                        root "/tmp/html/upload_from_client";
                        autoindex on;
                        limit_except GET {
                                deny all;
                        }
                }
		# you can set location based on request's extension
                location ~ .jpg { 
                        root "/tmp/data/photos";
                        client_body_buffer_size 8k;
                        client_max_body_size 1m;
                }
                location ~ .py{
                        cgi_script_pass "/tmp/cgi-bin/python-cgi";
                }
                location ~ .php{ 
                        cgi_script_pass "/tmp/cgi-bin/php-cgi";
                }
        }
        server {
                listen 80;
                listen [::]:80;
                server_name "" "wrong_host";
                return 404;
        }
	# This request will be redirected to naver.com
        server {
                listen 8080;
                location / {
                        return "http://www.naver.com";
                }
        }
}