https://github.com/akamlah/42-webserv
A simple HTTP 1.1 web server written in C++, mostly from scratch, for learning purposes.
https://github.com/akamlah/42-webserv
http-server network-programming posix-sockets
Last synced: 2 months ago
JSON representation
A simple HTTP 1.1 web server written in C++, mostly from scratch, for learning purposes.
- Host: GitHub
- URL: https://github.com/akamlah/42-webserv
- Owner: akamlah
- Created: 2022-09-01T12:24:39.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-11-26T15:21:50.000Z (over 2 years ago)
- Last Synced: 2025-01-25T19:08:32.318Z (4 months ago)
- Topics: http-server, network-programming, posix-sockets
- Language: C++
- Homepage:
- Size: 24.4 MB
- Stars: 1
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# webserv
### A 42 projectA simple HTTP 1.1 web server written in C++.
The aim of this project is to learn the theory behind network programming: only a few C functions related to socket programming were allowed, so tht we had to face the HTTP parsing and response handeling ourselves. The multiplexing part is handeled using poll() for siplicity; we don't use threads.
We set up our own simple config structure based on the requirements. A default configuration is provided if no file is selected when starting the sever.## Usage
At the root of the repository:
```
make
./webserv [ path of config file ]
```### Configuration
You can configure multiple servers, serving different pages on different ports.
To configure one server, open a server block like so:```
server {
}
```
Inside this block, you have to provide at least a host, a port, the root of your webpage's directory and the index file. Each field have to contain a value. If the functionality is optional but not requered the non or off world has to be there.
--> cgi: .php; (the webpage contain php code)
--> cgi: non; (the webpage don't run any cgi)
--> limit_body: -1; (no limit)Example configuration (with minimal requered fields):
```
server {
host: localhost;
port: 4242;
root: ./example_sites/http;
index: index.html;
server_name: non;
error: non;
limit_body: -1;
http_methods: GET;
http_redirects: non;
location: [];
directory_listing: off;
download: non;
cgi: non;
}
```Example configuration (with all fields set with correct syntax):
([...] ... [...]: meaning that multiple location blockes can be fused one after each other but obviously they have to be filled up)```
server {
host: localhost;
port: 5555;
root: ./example_var/example_www;
index: index.php;
server_name: exampleserver.awesome;
error: 501:/error/501.html, 400:/error/400.html;
limit_body: 1024;
http_methods: GET, POST;
http_redirects: https://en.wikipedia.org/wiki/Quantum_mechanics;
directory_listing: on;
download: ./downloads;
cgi: .php;
location: [
folder: http;
root: ./example_var/something/;
index: index.html;
http_methods: GET;
http_redirects: non;
directory_listing: off;
download: non;
cgi: non;
]
[...] ... [...]
;
}
```### Cgi
Our server suports two Common Gateway Interface (cgi): php and perl. For php-cgi we use the standard binary of php-cgi. In the case of perl we wrote a simple perl-cgi on our own. What will run the code in perl. It suports embed perl in html code.